cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Kevin_Maxwell
Level: Powered On

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
Community Support Team
Community Support Team

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
KroonOfficeSol
Level 10

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?

Kevin_Maxwell
Level: Powered On

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.

KroonOfficeSol
Level 10

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.

Kevin_Maxwell
Level: Powered On

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.

KroonOfficeSol
Level 10

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.
Community Support Team
Community Support Team

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
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,548)