cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
quacka
New Member

Update Data source with new values from gallery

I have a gallery that the datasource is from a sharepoint list

I want the user click a button and then all the items in the gallery will be updated with a new calculated values that I put into two labels. 

I tried adding a button outside the gallery and add the code below but it doesn't seem to do anything. Any idea what I done wrong?

ForAll(
    Gallery1_3.AllItems,
    Patch(
        'Salary Reviews',
        Gallery1_3.Selected,
        {
            'Current Approver': lblNextApprover,
            Status: lblNextStatus
        }
    )
)

 

6 REPLIES 6
mdevaney
Super User
Super User

@quacka 

I believe your 2nd argument in PATCH is not finding any matching record.  Gallery1_3.Selected will choose the latest gallery item clicked on but instead you want to target the current item in the loop.  Here's my suggestion assuming that the gallery is based on the Salary Reviews datasource.

 

ClearCollect(
    myGalleryItems,
    Gallery1_3.AllItems
);
ForAll(
    myGalleryItems
    Patch(
        'Salary Reviews',
        ID = myGalleryItems[@ID],
        {
            'Current Approver': lblNextApprover,
            Status: lblNextStatus
        }
    )
)

 

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Thanks for the quick response @mdevaney 


I thought the selected will give me the current item in the forall loop 😞

 

I tried to alter my code to what you given but it doesn't seem to like the pointer line for the ID as well. 

 

 ID = myGalleryItems[@ID],

 

Removing the above line below doesn't give me any errors in the formula but it doesn't update these records. It started to complain about missing data in mandatory field. I am not sure if it's trying to add new records instead of updating existing ones.

 

ClearCollect(
    myGalleryItems,
    Gallery1_3.AllItems
);
ForAll(
    myGalleryItems,
    Patch(
        'Salary Reviews',
        {
            'Current Approver': lblNextApprover,
            'Status': lblNextStatus
        }
    )
)

 

 

@quacka 

What error do you get for this line of code?

 ID = myGalleryItems[@ID],

 

One more question: is the datasource for Gallery1_3 'Salary Reviews'? 

@mdevaney 

ID = myGalleryItems[@ID],

Just gives  a generic errors: The function 'ForAll' has some invalid arguments. The function 'Patch' has some invalid arguments

You are right, the datasource for Gallery1_3 is  'Salary Reviews'

I might be doing this not optimal and long winded. I am actually not needing to use labels in a gallery. I was just just using them as a temporary placeholders for the update formula. There is no user manipulation required so logically i don't need to use a gallery.

Gallery1_3 data source 'Salary Reviews'
Items:

 

Filter(
    'Salary Reviews',
    'Current Approver'.Email in User().Email,
    Status.Value <> "Draft"
)

 


lblNextApprover:

 

If(
    Status.Value = "1st Approver" && !IsBlank('2nd Approver'.Claims),
    '2nd Approver'.Claims,
    Status.Value = "2nd Approver" && !IsBlank('3rd Approver'.Claims),
    '3rd Approver'.Claims,
    Status.Value = "3rd Approver" && !IsBlank('4th Approver'.Claims),
    '4th Approver'.Claims,
    Status.Value = "4th Approver"&& !IsBlank('5th Approver'.Claims),
    '5th Approver'.Claims,
    ""
)

 

lblNextStatus:

 

If(
    Status.Value = "1st Approver" && IsBlank('2nd Approver'.Claims),
    "Completed",
    Status.Value = "2nd Approver" && IsBlank('3rd Approver'.Claims),
    "Completed",
    Status.Value = "3rd Approver" && IsBlank('4th Approver'.Claims),
    "Completed",
    Status.Value = "4th Approver" && IsBlank('5th Approver'.Claims),
    "Completed",
    Status.Value = "1st Approver",
    "2nd Approver",
    Status.Value = "2nd Approver",
    "3rd Approver",
    Status.Value = "3rd Approver",
    "4th Approver",
    Status.Value = "4th Approver",
    "5th Approver",
    "Completed"
)

 


Logically  I can just do a forall function directly to 'Salary Reviews' with with the Items filter I have for the gallery. Then do a patch to update the 'Current Approver' and 'Status' field in a nested If for all the filtered records.

I can never get this to work though so I thought of doing it through a gallery instead.

On another note, 'Salary Reviews' is a SharePoint Online list. Column 'Status' is an option field. I am not sure passing it a display value like above will work or is it expecting index values to set it's values.

I am thinking if I add a tick box to the gallery and make the button go through the gallery and update any items with this ticked. Would this make it easier?

 

I am running out of ideas right now

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 (2,854)