cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
landonjochim
Resolver I
Resolver I

Power Apps Forms SharePointIntegration.Selected Contains Previous Selected Item's Data

Overview: I am running into an issue where I am creating a Collection when a user clicks on a List Item. The issue is that whenever a user clicks on a List Item, the collection is being populated with the previous selected item's data.

 

My setup: In the SharePointIntegration: OnView property

  1. Clear the collection for any previous selected list items
  2. Set a variable
  3. Split a MultiLineText field called "VendorContact" from within the selected list item. Notice that my source for the Split is SharePointIntegration.Selected. Then for each Result of the split, add to the collection.
  4. Show the user the form, ViewForm(SharePointForm1)
Clear(colVendorContacts);
Set(
    varNewContact,
    false
);
ForAll(
    Split(
        SharePointIntegration.Selected.VendorContact,
        "; "
    ),
    Collect(
        colVendorContacts,
        {
            Name: First(
                Split(
                    Result,
                    "-"
                )
            ).Result,
            ContactType: Last(
                FirstN(
                    Split(
                        Result,
                        "-"
                    ),
                    2
                )
            ).Result,
            State: Last(
                FirstN(
                    Split(
                        Result,
                        "-"
                    ),
                    3
                )
            ).Result,
            Email: Last(
                FirstN(
                    Split(
                        Result,
                        "-"
                    ),
                    4
                )
            ).Result,
            PhoneNumberCell: Last(
                FirstN(
                    Split(
                        Result,
                        "-"
                    ),
                    5
                )
            ).Result,
            PhoneNumberDesk: Last(
                FirstN(
                    Split(
                        Result,
                        "-"
                    ),
                    6
                )
            ).Result
        }
    )
);
ViewForm(SharePointForm1)

 

What is happening: 

(When opening list and the first time you select a item)

  1. Form shows all correct data except for the collection, which is blank
  2. Select a different item
  3. Form shows all correct data except for the collection, which is showing the previously selected items data
  4. This continues regardless to the number of items you select. The collection is always the previously selected items data

 

I am absolutely willing to provide more detail where needed. Any help would be great! 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@landonjochim 

Your ForAll is backward...ForAll produces a table.  Are you adding or removing or altering records of the collection you are bringing in?  If so, a collection is fine, otherwise it is overhead.

Your formula should be as follows to use the ForAll as intended. Note: there were a couple of syntax issues with the first suggestion (sorry, we type these things by hand in the forum without the formula editor):

Set(varNewContact, false );

With({_record: LookUp(ProductServices,ID=SharePointIntegration.SelectedListItemID)},
    ClearCollect(colVendorContacts,
        ForAll(
            Filter(Split(_record.VendorContact, "; "), !IsBlank(Result)) As _item,
                With({_row: Split(_item.Result, "-")},
                    {Name: Last(FirstN(_row.Result, 1)).Result,
                    ContactType: Last(FirstN(_row.Result, 2)).Result,
                    State: Last(FirstN(_row.Result, 3)).Result,
                    Email: Last(FirstN(_row.Result, 4)).Result,
                    PhoneNumberCell: Last(FirstN(_row.Result, 5)).Result,
                    PhoneNumberDesk: Last(FirstN(_row.Result, 6)).Result
                    }
                )
        )
    )
);

ViewForm(SharePointForm1)

 

 

When I take that formula and test it out with this:

With({VendorContact:"abc-def-ghi-jkl-mno-pqr; pqr-mno-jkl-ghi-def-abc"},
    ClearCollect(colVendorContacts,
        ForAll(
            Filter(Split(VendorContact, "; "), !IsBlank(Result)) As _item,
                With({_row: Split(_item.Result, "-")},
                    {Name: Last(FirstN(_row.Result, 1)).Result,
                    ContactType: Last(FirstN(_row.Result, 2)).Result,
                    State: Last(FirstN(_row.Result, 3)).Result,
                    Email: Last(FirstN(_row.Result, 4)).Result,
                    PhoneNumberCell: Last(FirstN(_row.Result, 5)).Result,
                    PhoneNumberDesk: Last(FirstN(_row.Result, 6)).Result
                    }
                )
        )
    )
);

It results in :

RandyHayes_0-1630080649302.png

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

6 REPLIES 6
RandyHayes
Super User
Super User

@landonjochim 

Please consider changing your Formula to the following:

Set(varNewContact, false);

With(LookUp(yourDataSource, ID=SharePointIntegration.SelectedListItemID)
    Set(colVendorContacts,
        ForAll(
            Filter(Split(VendorContact, "; "), !IsBlank(Result)),
            With(Split(Result, "-"),
            {Name: Last(FirstN(Result, 1)).Result
             ContactType: Last(FirstN(Result, 2)).Result
             State: Last(FirstN(Result, 3)).Result,
             Email: Last(FirstN(Result, 4)).Result,
             PhoneNumberCell: Last(FirstN(Result, 5)).Result,
             PhoneNumberDesk: Last(FirstN(Result, 6)).Result
            }
        )
    )
);

ViewForm(SharePointForm1)

In the above (beside a little more streamlined and not consuming the overhead for a collection), the reliance is on the SelectedListItemID instead of the selectedItem.

 

I tend to find that property a little more reliable.

 

See if that makes any difference.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thanks for the reply! Using the With() function did help and maybe I wasn't detailed enough in my post, but I did need to still use the collect to get all of the data from the Split(VendorContacts). 

Clear(colVendorContacts);

Set(varNewContact, false );

With(LookUp(ProductServices,ID=SharePointIntegration.SelectedListItemID),
    ForAll(
        Split(VendorContact,"; "),
            Collect(colVendorContacts,
            {                 
                Name: First(Split(Result,"-")).Result,
                ContactType: Last(FirstN(Split(Result,"-"),2)).Result,
                State: Last(FirstN(Split(Result,"-"),3)).Result,
                Email: Last(FirstN(Split(Result,"-"),4)).Result,
                PhoneNumberCell: Last(FirstN(Split(Result,"-"),5)).Result,
                PhoneNumberDesk: Last(FirstN(Split(Result,"-"),6)).Result 
            }
        )
    )
);

ViewForm(SharePointForm1)

Anyway, my first column in my collect, "Name", is not working correctly. Instead it is saving the data in a "{Name}" column in the collection. Any thoughts?

landonjochim_0-1630079883546.png

 

Thanks!

 

RandyHayes
Super User
Super User

@landonjochim 

Your ForAll is backward...ForAll produces a table.  Are you adding or removing or altering records of the collection you are bringing in?  If so, a collection is fine, otherwise it is overhead.

Your formula should be as follows to use the ForAll as intended. Note: there were a couple of syntax issues with the first suggestion (sorry, we type these things by hand in the forum without the formula editor):

Set(varNewContact, false );

With({_record: LookUp(ProductServices,ID=SharePointIntegration.SelectedListItemID)},
    ClearCollect(colVendorContacts,
        ForAll(
            Filter(Split(_record.VendorContact, "; "), !IsBlank(Result)) As _item,
                With({_row: Split(_item.Result, "-")},
                    {Name: Last(FirstN(_row.Result, 1)).Result,
                    ContactType: Last(FirstN(_row.Result, 2)).Result,
                    State: Last(FirstN(_row.Result, 3)).Result,
                    Email: Last(FirstN(_row.Result, 4)).Result,
                    PhoneNumberCell: Last(FirstN(_row.Result, 5)).Result,
                    PhoneNumberDesk: Last(FirstN(_row.Result, 6)).Result
                    }
                )
        )
    )
);

ViewForm(SharePointForm1)

 

 

When I take that formula and test it out with this:

With({VendorContact:"abc-def-ghi-jkl-mno-pqr; pqr-mno-jkl-ghi-def-abc"},
    ClearCollect(colVendorContacts,
        ForAll(
            Filter(Split(VendorContact, "; "), !IsBlank(Result)) As _item,
                With({_row: Split(_item.Result, "-")},
                    {Name: Last(FirstN(_row.Result, 1)).Result,
                    ContactType: Last(FirstN(_row.Result, 2)).Result,
                    State: Last(FirstN(_row.Result, 3)).Result,
                    Email: Last(FirstN(_row.Result, 4)).Result,
                    PhoneNumberCell: Last(FirstN(_row.Result, 5)).Result,
                    PhoneNumberDesk: Last(FirstN(_row.Result, 6)).Result
                    }
                )
        )
    )
);

It results in :

RandyHayes_0-1630080649302.png

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Yes that is working for me. I am still getting the "{Name}" column within my collection - it is blank. But the data is correctly being placed within the "Name" column. 

 

To answer your question, yes. I am adding, removing, modifying the collection. Thanks for helping me get to a much more efficient application.

RandyHayes
Super User
Super User

@landonjochim 

Your {Name} column is a ghost.  If you save, exit and load again, it will be gone.  If not, I would be concerned that something else in your app is impacting that, and you WOULD want to determine what it is as it is a schema mismatch issue.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

You are correct. That column is no longer showing. Thanks Randy

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,900)