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

Edit/Create an item in a SharePoint List based on gallery based on Gallery - ForAll, Patch and If

Hi, I'm stuck in a formula getting some errors so not really sure if it is possible to achieve what I want. The formula is using ForAll, If and Patch to update some items from a gallery in a SharePoint List.

 

The SP List, MySPList, has 3 columns: SPID (This number is a variable IDVar), Type and Impact

The Gallery1 has 3 elements.

  • Item_Check (Check box)
  • Item_Type (Label - Number)
  • Item_Impact (TextInput)

The Gallery is a filtered gallery of all Types from MySPList where SPID=IDVar

 

The functionality is, when I click on a button, all elements of the Gallery checked (Item_Check=true) should be either updated or created depending if they previously exist. What I'm doing is a lookup to find the item by SPID and Type and if it is empty, create the item with Patch, otherwise edit with Patch.

 

The code is something like that but first, it is not working and secondly I'm getting some delegation errors (that i dont know why) I

 

FORALL(Gallery1.AllItems,
  IF(Item_Check=True,
    IF(!IsBlank(LookUp(MySPList,SPID=IDVar && Type = Value(Item_Type.Text))),
      Patch(MySPList,LookUp(MySPList,SPID=IDVar && Type = Value(Item_Type.Text)){SPID:IDVar, Type: Item_Type, Impact:Item_Impact}),
      Patch(MySPList,Defaults(MySPList),{SPID:IDVar, Type: Item_Type, Impact:Item_Impact})))

  

 

any help is welcome

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Sam4
Resolver I
Resolver I

Spoiler
I'm replying to myself as I've been able to progress with this so leaving the reply if that can help someone.

I had two problems:

- Delegation: I've solved taking out the LookUp of the FORALL and adding a non-visible item in the gallery with the SP ID. Then in the ForAll I'm using this item to identify where I am updating the data

- Sintaxis: Several errors fixed. The code finally stays like this

ForAll(Gallery1.AllItems, 
  If(Item_Check.Value=true, 
    If(IsBlank(ItemSPID.Text),Patch(MySPList,Defaults(MySPList),{SPID:IDVar, Type: Item_Type, Impact:Item_Impact.Text}),Patch(MySPList,{SPID:IDVar, Type: Item_Type, Impact:Item_Impact.Text}))))​



View solution in original post

1 REPLY 1
Sam4
Resolver I
Resolver I

Spoiler
I'm replying to myself as I've been able to progress with this so leaving the reply if that can help someone.

I had two problems:

- Delegation: I've solved taking out the LookUp of the FORALL and adding a non-visible item in the gallery with the SP ID. Then in the ForAll I'm using this item to identify where I am updating the data

- Sintaxis: Several errors fixed. The code finally stays like this

ForAll(Gallery1.AllItems, 
  If(Item_Check.Value=true, 
    If(IsBlank(ItemSPID.Text),Patch(MySPList,Defaults(MySPList),{SPID:IDVar, Type: Item_Type, Impact:Item_Impact.Text}),Patch(MySPList,{SPID:IDVar, Type: Item_Type, Impact:Item_Impact.Text}))))​



Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (3,654)