cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
abd3127
Kudo Kingpin
Kudo Kingpin

Populate data from two galleries in a collection and then editing the data in another gallery

Hi Team,

 

I need to create a app in which we accept data from user in two different galleries via text input (Show in picture 1).

The data is Budget Title,Dept Code, Initiative, Dept ID.

 

The budget title,Dept Code and dept id are stored in a SP list. As there can be number of initiatives we needed to store that data in another sp list along with budget title,Dept Code and dept id (One budget title linked to these initiatives.)

 

On main landing page, we populate data of main list (budget title and the dept id, dept code)

So now when i click on one of the budget title, i move on to edit page where i store the data of this particular budget title filtered in a collection and use this collection to populate galleries.

Here now i want to update the single entry in my second sp list (Changes in initiative ).

 

So i'm using patch function to update the data, to get the ID of this particular record i'm using lookup. In the lookup formula i get budget title, dept id , dept code.But i can not get this particular initiative id to update it. (Or to repatch the data in all the previous records)

 

Please find attached files for referrence.

Collect formula to store records when on edit screen

ClearCollect(
    Results,
    Filter(' DEMO LIST',DeptCode = Gallery1.Selected.DeptCode)
);

Lookup Formula

ForAll(
    Gallery2_2.AllItems ,
    If(!IsBlank(TextInput3_2.Text) , Patch (
        'DEMO LIST',
        LookUp(' DEMO LIST',DeptCode=Gallery1.Selected.DeptCode && Title = {?? Initiative Title ??} )  ,
        {
            Title: TextInput3_2.Text,
            DeptID: TextInput4_2.Text,
                                                                                                           }
    )
));

Please suggest some ideas on how i can get the specific id of the records?

1 ACCEPTED SOLUTION

Accepted Solutions

Ok, so clearly it requires some closer looking into - and I'm going to have to make some big assumptions here, so let's hope I'm right otherwise this is a lot of typing for nothing Man Wink

 

Let's assume all your keys and lookups are correct (If this sounds alien to you, check out this post to see if what I'm saying makes sense.)

 

Here's my understanding;

Screen1 -> Gallery1 -> All List1 Items.

Screen2 -> Gallery2 -> All List2 Items that belong to the item selected in Gallery1

 

You're then checking each item in the Gallery2 to see if one of the fields has data in it, (presumably it was blank before and now someone has typed something in there using a Text Input control....Big assumption #1, I assume you're using editable text fields in Gallery2 instead of a separate form?  What happens if there was data in it previously?)

 

If it does have something in it, you want to update that specific item in List2.

 

To patch the specific item in List2, you need to refer to that specific item in the list when you patch it.  This should amount to something as simple as

 

Patch(List2, Find List2 Item, {ColumnA: Value, ColumnB: Value})

To Find List2 Item you're using a Lookup, and this is where you're getting stuck because you're currently operating inside a ForAll and have to effectively identify the current ForAll item in the target source - big assumption #2

 

 

Something like;

 

For all of the items in Gallery2_2, 
        where there's some text in the text field for the Gallery2_2 item we're currently looking at, 
               Patch(
                      List2, 
                         find the List2 record that matches this Gallery2_2 record, 
                         update {ColumnA: Text field value, ColumnB: Other Text field value}))

If this is the case, then you may be looking for disambiguation - because your collected column name and your source column names are the same.  I would still use the List2 unique identifier ID column as my reference, but you can replace my logic with whatever lookup column you're using.

 

 

Also, in my experience, you can't disambiguate Gallery.AllItems fields (bummer, sorry), so you would need to collect your changes into a collection before you patch them back.  Here's how I would do it after you've edited some fields in your Gallery;

 

Button, Onselect:

ClearCollect(collectGalleryChanges, Gallery2.AllItems);  //collects all Gallery items into a collection, including the values of any TextInput fields.

ForAll(
    collectGalleryChanges,
    If(
        !IsBlank(TextInput3_2.Text),
        Patch(
            'DEMO LIST',
            LookUp(
                'DEMO LIST',
                ID = collectGalleryChanges[@ID]  //disambiguation
            ),
            {Value: TextInput3_2.Text}
        )
    )
)

big assumption #3 - 'DEMO LIST' is your second list...

 

Hope this makes sense 🙂

 

Kind regards,


RT

 

View solution in original post

4 REPLIES 4
RusselThomas
Microsoft
Microsoft

Hi @abd3127 ,

 

Ok, so quick disclaimer and confession - I probably need to look at this in more detail, but at first glance my first quick question to ask is; can you not use the SPO list ID column that is auto-generated for each row of data in the list?


You might not see it in your SharePoint list view because the default view hides it - but it is there and accessible to PA, along with the other auto-generated columns like Created, Created by, Modified, Modified by etc. etc.

 

So something like;

LookUp(' DEMO LIST', ID = Gallery1.Selected.ID)

Otherwise I clearly didn't understand the question and need to look at it a little closer 🙂

 

Kind regards,

 

RT

 

 

Hi @RusselThomas 

You understood my problem but the thing is i have two diff SP Lists.

First one contains budget title and Dept Code.

Second list contains Inititiatives (As i am accepting input in gallery there can be many inititiatives), budget title, dept code, dept id.

Now as i dont want my gallery to show all the initiatives, i am populating data from first list (Only budget title and dept code.)

So according to your formula i will get the id from first list and not the second.

Here i want to update the initiatives in second list .

 

Thanks for the reply !!

Ok, so clearly it requires some closer looking into - and I'm going to have to make some big assumptions here, so let's hope I'm right otherwise this is a lot of typing for nothing Man Wink

 

Let's assume all your keys and lookups are correct (If this sounds alien to you, check out this post to see if what I'm saying makes sense.)

 

Here's my understanding;

Screen1 -> Gallery1 -> All List1 Items.

Screen2 -> Gallery2 -> All List2 Items that belong to the item selected in Gallery1

 

You're then checking each item in the Gallery2 to see if one of the fields has data in it, (presumably it was blank before and now someone has typed something in there using a Text Input control....Big assumption #1, I assume you're using editable text fields in Gallery2 instead of a separate form?  What happens if there was data in it previously?)

 

If it does have something in it, you want to update that specific item in List2.

 

To patch the specific item in List2, you need to refer to that specific item in the list when you patch it.  This should amount to something as simple as

 

Patch(List2, Find List2 Item, {ColumnA: Value, ColumnB: Value})

To Find List2 Item you're using a Lookup, and this is where you're getting stuck because you're currently operating inside a ForAll and have to effectively identify the current ForAll item in the target source - big assumption #2

 

 

Something like;

 

For all of the items in Gallery2_2, 
        where there's some text in the text field for the Gallery2_2 item we're currently looking at, 
               Patch(
                      List2, 
                         find the List2 record that matches this Gallery2_2 record, 
                         update {ColumnA: Text field value, ColumnB: Other Text field value}))

If this is the case, then you may be looking for disambiguation - because your collected column name and your source column names are the same.  I would still use the List2 unique identifier ID column as my reference, but you can replace my logic with whatever lookup column you're using.

 

 

Also, in my experience, you can't disambiguate Gallery.AllItems fields (bummer, sorry), so you would need to collect your changes into a collection before you patch them back.  Here's how I would do it after you've edited some fields in your Gallery;

 

Button, Onselect:

ClearCollect(collectGalleryChanges, Gallery2.AllItems);  //collects all Gallery items into a collection, including the values of any TextInput fields.

ForAll(
    collectGalleryChanges,
    If(
        !IsBlank(TextInput3_2.Text),
        Patch(
            'DEMO LIST',
            LookUp(
                'DEMO LIST',
                ID = collectGalleryChanges[@ID]  //disambiguation
            ),
            {Value: TextInput3_2.Text}
        )
    )
)

big assumption #3 - 'DEMO LIST' is your second list...

 

Hope this makes sense 🙂

 

Kind regards,


RT

 

View solution in original post

Hello @RusselThomas 

 

All your assumptions were correct !

And the solution worked like charm !!

 

Now i am able to update the new data in the second list.

Thank you for your help Smiley Happy

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (30,648)