cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted

Reference Current Record of ForAll

I'll try to describe the scenario accurately.

 

One SP list contains items that define products.  For each item (product) I want to create a corresponding record in a SP totals list.  So record 1 in the totals list would have Product1 in it (a lookup field, BTW), record 2 has Product2 and so on.

 

What I am usng is a ForAll(products, Patch(Totals, ....

 

If I only Patch values for text fields in the list, I get the correct number of new records.  However, I am not able to Patch the Product lookup field because I have not been able to construct the correct ID value which would come from the current record being processed in the ForAll loop.

 

I have a similar problem with a PowerApps that is copying records from one list to another.  Same product field.  In this case, I collect the items from List 1 and reference in a gallery.  Then a ForAll on that collection Patches into a new collection.  All of the fields come across just fine excpet for the Product field.  In record 1, instead of the value from the source list, it is a differnt value; same as record 3, and all the others are blank.

 

There seems to be some similarity between the two.

 

Any ideas>

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Reference Current Record of ForAll

I have figured it out.

 

 ForAll(colStores,
    Patch(colDailySalesTotals,Defaults(colDailySalesTotals),
          {Store:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:ID,Value:Title},
            StoreText:Title}))

 

The result is that one item is created in colDailySalesTotals for each itemin colStores, and the column Stores (a lookup fiel;d) in colDailySalesTotals is set to the corresponding Store value in colStores where it is the Title column.  StoreText is the store name as a text field.

 

 

2 REPLIES 2
Community Support Team
Community Support Team

Re: Reference Current Record of ForAll

Hi @lmheimendinger,

Based on the issue that you mentioned, I think you have faced a Disambiguation issue with same column name in different SP lists, is it true?

If the products SP list and the Totals SP list have same columns, when you reference the column within the Patch function, PowerApps may not know where the column is from? products SP list or Totals SP list?

In order to fix this issue, I think the Disambiguation operator (@) could achieve your needs. More details about the Disambiguation operator (@), please check the following article:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/operators#disambiguation-oper...

I assume that the products SP list and the Totals SP list has same column name -- ProductColumn. On your side, please modify your ForAll formula as below:

ForAll(
    products, 
    Patch(
       Totals,
       Defaults(Totals),
       {
         ...
         ProductColumn: products[@ProductColumn],
         ...
       }
   )
)

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Re: Reference Current Record of ForAll

I have figured it out.

 

 ForAll(colStores,
    Patch(colDailySalesTotals,Defaults(colDailySalesTotals),
          {Store:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:ID,Value:Title},
            StoreText:Title}))

 

The result is that one item is created in colDailySalesTotals for each itemin colStores, and the column Stores (a lookup fiel;d) in colDailySalesTotals is set to the corresponding Store value in colStores where it is the Title column.  StoreText is the store name as a text field.