Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

For all Gallery patch

(1) ShareShare
ReportReport
Posted on by 69

Good day

I have a gallery that always consist of four records with various fields. I want to use two of the fields the unique identifier named Website_ID and the Form_URL field values which holds values for the four records to update a corresponding unique identifier in another table named Contacts. The four fields that must be updated in the Contacts table has different names.

My formula is:

ForAll(Gallery1.AllItems, Patch(Contacts, First (Filter (Contacts, Contact_ID =Website_ID)), {Assessment_form1:Form_URL, Assessement_form2:Form_URL,Assessement_form3:Form_URL,Assessement_form4:Form_URL}))

The problem is that the formula does not loop through the gallery- it writes the same Form_URL value to each of the different fields in the Contacts table.

Regards

Alwyn

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    WarrenBelz 145,422 on at
    Re: For all Gallery patch

    @AlwynSchutte ,

    The fundamental issue is that if you want to differentiate between the gallery Items, you need a different identifier for each that then has to match the target record in the list you are patching to. If your "bulky code works, then stick with it, although my approach would be to have a different data structure from the outset.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • AlwynSchutte Profile Picture
    AlwynSchutte 69 on at
    Re: For all Gallery patch

    Good day 

    Website_ID in the gallery are all the same values which is exactly the same value as Contact_ID in the Contacts table. In the Contacts table Contact_ID is a unique number. In the gallery the business rules dictate that four of the same assessments of the same applicant must be grouped together. So the Website_ID of the Gallery which is the same value for all four records must be matched to the Contact_ID in the Contacts table which is a unique value. The Form_URL are all different values and this is the problem. The different values are not written to the Contacts table. The fourth value of Form_URL of the Gallery is written to all fields in the Contacts table.

    Attached you will see on the picture exactly what the current problem is. As I explained above I overcame the problem with some bulky code- but it is not ideal.

  • AlwynSchutte Profile Picture
    AlwynSchutte 69 on at
    Re: For all Gallery patch

    Good day

    Tested the code but it only writes to Assessment_form1

     

  • AlwynSchutte Profile Picture
    AlwynSchutte 69 on at
    Re: For all Gallery patch

    Good day

    The Gallery has four identifiers named WebSite_ID which are all the same value. Another field named Form_URL has all different values. I want to lookup the Website_ID of the gallery in the Applications table in the field named Contact ID and write the four different values of the Form_URL field in the gallery to the fields named Assessment_form1, Assessment_form2, Assessment_form3 and Assessment_form4. The record in the Applications table is found but the fourth value of the Form_URL field of the gallery is written to all of the fields in the Applications table instead of the four different values.

    Attached the picture will clearly explain what the problem is.

     

  • Verified answer
    WarrenBelz Profile Picture
    WarrenBelz 145,422 on at
    Re: For all Gallery patch

    Hi @AlwynSchutte ,

    Firstly can I assume that both Contact_ID and FormURL are different for each record in the gallery - your screenshot suggests Contact_ID is not. Do you have another unique identifier for the record that is also in the Gallery Items ?

    If so

    ForAll(
     Gallery1.AllItems As aPatch
     Patch(
     Contacts, 
     LookUp(
     Contacts, 
     Identifier = aPatch.Identifier
     ), 
     {
     Assessment_form1: aPatch.Form_URL, 
     Assessement_form2: aPatch.Form_URL,
     Assessement_form3: aPatch.Form_URL,
     Assessement_form4: aPatch.Form_URL
     }
     )
    )

    Also when you say it keeps writing the same value to the different fields in the contacts table - what exactly do you mean by that ?

  • poweractivate Profile Picture
    poweractivate 11,078 on at
    Re: For all Gallery patch

    @AlwynSchutte 

     

    To make your temporary measure better, you can try this:

     

    //pseudocode - not tested
    ClearCollect(tempCollect,{})
    ForAll(Sequence(CountRows(Gallery1.AllItems)),
     Select(Gallery1,CountRows(tempCollect));
     Collect(tempCollect,{});
     Patch(Applications,First(Filter(Applications,'Contact ID'=Gallery1.Selected.Website_ID)),{'Assessment form1':Gallery1.Selected.Form_URL});
    )

     

    I did not test the above, I do not know if it even works.

     

    Even if it somehow works, the above is not a good practice at all, it's just something quick in case you need it in a hurry or something.

    I strongly recommend that you check with @WarrenBelz further on why your issue is occurring.

     

    You should figure out why the formula @WarrenBelz gave originally was not working in your case. I would like you to double check and make sure you did use the original formula given exactly, and that (if needed) you used appropriate values for your scenario. 

     

    I could not see any issue with the formula really, it looks like it should work to me.

     

    However, if it is still not working in your case, even after you checked it again, I would ask you to check with @WarrenBelz  for any further questions on this specific thread, as I do not have much time at the moment to go into an in-depth testing of the formula, ForAll, Gallery.AllItems, etc. for the possible causes of this specific issue.

     

    In order to see if there is some issue, I would need to do some checking in-depth, and it's something I'm not available to do at the moment, so please check with @WarrenBelz for any further assistance on this issue, if it persists.

     

    I hope the revised temporary measure I gave may help you, for the very short term.

  • poweractivate Profile Picture
    poweractivate 11,078 on at
    Re: For all Gallery patch

    @AlwynSchutte 

     


    @AlwynSchutte wrote:

    ...it keeps writing the same value to the different fields in the contacts table...

     


    Please clarify what you mean by this.

     

    Do you mean the same Record from that Table is being overwritten each time, and instead you are expecting different individual Records to be written, but only the one Record is updated, so you get a result of only one Record being updated - when you expect multiple individual Records to be updated  - is this correct?

     

    Or, do you mean that the correct different individual Records are updated, however, it is using same values instead of different values?

    If so, which of the same values is it using? Does it tend to be stuck on a particular Gallery Item instead of looping through them? If so, which specific Gallery Item's values is it using to update all the Records? (e.g. is it the very first one? the very last one? Something else?) I was wondering if you could clarify it.

     

    or, did you mean something else entirely?

  • AlwynSchutte Profile Picture
    AlwynSchutte 69 on at
    Re: For all Gallery patch

    The Applications table as shown above is a new test table in dataverse I created to test.

  • AlwynSchutte Profile Picture
    AlwynSchutte 69 on at
    Re: For all Gallery patch

    Hi Warren

    It was just to show you the data of the Gallery which I am trying to write. I created a separate data table-just to show you the data. I have tried your formula a number of times on my Gallery1 and it keeps writing the same value to the different fields in the contacts table.

    As a temporary measure I got it to work with the following code but it is not ideal:

    Select(Gallery1,1);
    Patch(Applications,First(Filter(Applications,'Contact ID'=Gallery1.Selected.Website_ID)),{'Assessment form1':Gallery1.Selected.Form_URL});
    Select(Gallery1,2);
    Patch(Applications,First(Filter(Applications,'Contact ID'=Gallery1.Selected.Website_ID)),{'Assessment form2':Gallery1.Selected.Form_URL});
    Select(Gallery1,3);
    Patch(Applications,First(Filter(Applications,'Contact ID'=Gallery1.Selected.Website_ID)),{'Assessment form3':Gallery1.Selected.Form_URL});
    Select(Gallery1,4);
    Patch(Applications,First(Filter(Applications,'Contact ID'=Gallery1.Selected.Website_ID)),{'Assessment form4':Gallery1.Selected.Form_URL});

     

    Attached is my Gallery

    Regards

    Alwyn

  • WarrenBelz Profile Picture
    WarrenBelz 145,422 on at
    Re: For all Gallery patch

    HI @AlwynSchutte ,

    That is not a Gallery - it is a Data Table. Please try it in a Gallery as it should work.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,422

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,711

Leaderboard