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

How to loop collection lookup list values?

I have a collection called "Beneficiary_Collection" and a sharePoint list called "Beneficiary". In SP list I have a Lookup column called "Conditions" which it allows Multiple Values to be saved (Allow multiple values is enabled). With the following code, I'm trying to save multiple values to SP but it only saves the first value (Acceptable).

 

Collection has the following values: AcceptableActive

 

This is the way that it should be saved in SP:

1.JPG

But it saves like this in SP:

2.JPG

 

 

 

 

 

 

ForAll(Beneficiary_Collection,
Patch(Beneficiary,LookUp(Beneficiary, Beneficiary_ID = "50114"),
{
    Conditions: Table(
    {
           '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
           Id: LookUp(Conditions_Lookup, English_Def in Conditions.English_Def, ID),
           Value: LookUp(Conditions_Lookup, English_Def in Conditions.English_Def, English_Def)
           
    })
}))

 

I don't know how to Loop all values in the Collection Lookup column (Conditions) as it only selects the First value!

 

Any help would be greatly appreciated. Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Patch/Update Multiple Values to a SharePoint Lookup Column

Hevin,

 

Could you please share an example of the collection, specially for the Lookup field schema saved in this collection?

If the schema matches, then there is no need to specify the detailed mapping, you could just use the following code:

ForAll(Beneficiary_Collection,
Patch(Beneficiary,LookUp(Beneficiary, Beneficiary_ID = "50114"),
{
    Conditions: Collection_Conditions
}))

If the schema is not the same, then you will need to lookup the the corresponding table to find the related ID and value.

By the way, for the Lookup field, the recent changes make it available to be updated with the following schema:

{Id: ,

 Value:""}

Id should be provided a number value, while the Value should be string type.

 

If you could share more details about the collection used in your example, then we mgiht be able to offer a more suitable solution.

The workable patch within forall for the Multi-enabled field from my side is:

a workable way for the Lookup saved collection:

ForAll(RenameColumns(
RenameColumns(Collection1,"MultiLookup","CMultiLookup"),
"ID","CID"),
Patch(Patchtesting,
LookUp(Patchtesting,ID=CID),
{MultiLookup:CMultiLookup}))

A workable way for the Value saved collection:

ForAll(AddColumns(
RenameColumns(Collection1,"ID","CID"),
"MultiValue",MultiLookup.Value),
Patch(Patchtesting,
LookUp(Patchtesting,ID=CID),
{MultiLookup:ForAll(RenameColumns(MultiValue,"Value","CValue"),
{Id:LookUp(Choices(Patchtesting.MultiLookup),
Value=CValue,Id),Value:CValue})
})
)

Regards,

Michael

 

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

View solution in original post

6 REPLIES 6
Highlighted
Resident Rockstar
Resident Rockstar

Re: Patch/Update Multiple Values to a SharePoint Lookup Column

Probably It updates all the records from the collection, only to the same record in you're datasource. Because off this line:

Patch(Beneficiary,LookUp(Beneficiary, Beneficiary_ID = "50114")

Maybe the Beneficiary_ID should be dynamic based on a column in your collection, so it will look up a different record for each Patch?

Highlighted
Advocate I
Advocate I

Re: Patch/Update Multiple Values to a SharePoint Lookup Column

@KroonOfficeSol Thanks for your reply.

The problem is not the row. The problem is that in SP you can set the Lookup column to hold multiple values. In my case it only saves the first value from the multiple values.

Example:

 

In the Collection, Condition column has: Acceptable, Active as selected values. However, when I save it to SP, it only saves Acceptable and not the Active.

 

I just inserted new images in my post.

Highlighted
Resident Rockstar
Resident Rockstar

Re: Patch/Update Multiple Values to a SharePoint Lookup Column

Sorry for the wrong answer.

 

I don't have experience with lookup columns in SharePoint,but did a google search and find this threat:

https://powerusers.microsoft.com/t5/General-Discussion/How-to-patch-a-SharePoint-Lookup-Column/m-p/2...

 

I think you should get rid off the table part when I look at this function:

ForAll(Beneficiary_Collection,
Patch(Beneficiary,LookUp(Beneficiary, Beneficiary_ID = "50114"),
{
    Conditions: '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
           Id: LookUp(Conditions_Lookup, English_Def in Conditions.English_Def, ID),
           Value: LookUp(Conditions_Lookup, English_Def in Conditions.English_Def, English_Def)
}))

 

Hope this helps.

Highlighted
Advocate I
Advocate I

Re: Patch/Update Multiple Values to a SharePoint Lookup Column

No worries @KroonOfficeSol. Thanks for your time. I have seen that post but it didn't help me. I think I need to use ForAll for every Lookup value in Collection (Condition). But so far I have not been able to find the right syntax.

Highlighted
Resident Rockstar
Resident Rockstar

Re: Patch Multiple Values to a SharePoint Lookup Column

Thinking out off the box here, bit what I thinks happens is that the seconds post replaces the first in total instead off adding tge selection. Maybe you should first build a new collection with the three parameters you need to update the lookup and then do one patch with that collection as parameter. A collection = a table basically.

As I say thinking out off the box, but naybe this approach works.
Highlighted
Community Support
Community Support

Re: Patch/Update Multiple Values to a SharePoint Lookup Column

Hevin,

 

Could you please share an example of the collection, specially for the Lookup field schema saved in this collection?

If the schema matches, then there is no need to specify the detailed mapping, you could just use the following code:

ForAll(Beneficiary_Collection,
Patch(Beneficiary,LookUp(Beneficiary, Beneficiary_ID = "50114"),
{
    Conditions: Collection_Conditions
}))

If the schema is not the same, then you will need to lookup the the corresponding table to find the related ID and value.

By the way, for the Lookup field, the recent changes make it available to be updated with the following schema:

{Id: ,

 Value:""}

Id should be provided a number value, while the Value should be string type.

 

If you could share more details about the collection used in your example, then we mgiht be able to offer a more suitable solution.

The workable patch within forall for the Multi-enabled field from my side is:

a workable way for the Lookup saved collection:

ForAll(RenameColumns(
RenameColumns(Collection1,"MultiLookup","CMultiLookup"),
"ID","CID"),
Patch(Patchtesting,
LookUp(Patchtesting,ID=CID),
{MultiLookup:CMultiLookup}))

A workable way for the Value saved collection:

ForAll(AddColumns(
RenameColumns(Collection1,"ID","CID"),
"MultiValue",MultiLookup.Value),
Patch(Patchtesting,
LookUp(Patchtesting,ID=CID),
{MultiLookup:ForAll(RenameColumns(MultiValue,"Value","CValue"),
{Id:LookUp(Choices(Patchtesting.MultiLookup),
Value=CValue,Id),Value:CValue})
})
)

Regards,

Michael

 

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

View solution in original post

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

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