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

Powerapps update LookUp Column (multi-select)

Hi,

I'm trying to update my SharePoint list order which contains a lookup column named positions.
positions itself contains some data of one order position. In list order the column positions is multi selectable.
So my next step is to add a new item to positions regarding to an item in order.
That is why I want to update the multi-select lookup column in order with the new added item of positions, so that the values before updating are still in that column plus the new added one.

NID and PID are global variables.

I tried with patch: 

Patch(
  LookUp(
    order;
    ID = NID;
    positions
   );
  Defaults(
    LookUp(
      order;
      ID = NID;
      positions
    )
  );
  {
    Id: PID;
    Value: LookUp(
      positions;
      ID = PID;
      toShow
    )
  }
)

and I also tried with collect

Collect(
  LookUp(
    order;
    ID = NID;
    positions
  );
  {
    '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference";
    Id: PID;
    Value: LookUp(
      positions;
      ID = PID;
      toShow
    )
  }
)

To test I saved the current item in a context variable. With both methods for the context variable that works fine.
But the changes won't update to the actual SharePoint list.

Mysteriously this piece of code worked but merged only the first item with the new one (obviously)

Patch(
	order;
	First(
		Filter(
			order;
			ID = NID
		)
	);
	{
		positions: Table(
			First(
				LookUp(
					order;
					ID = NID;
					positions
				)
			);
			{
				Id: PID;
				Value: LookUp(
					positions;
					ID = PID;
					toShow
				)
			}
		)
	}
)



Is there some hidden woodo magic missing?

Thanks in advance

PS.: the ; are correct here instead of the normal ,

1 ACCEPTED SOLUTION

Accepted Solutions
v-yutliu-msft
Community Support
Community Support

Hi @Ascawath ,

Do you want to update a multiple look-up column?

If you want to use the original data, I suggest you two ways:

1)use edit form

Set the edit form's Item:

First(
		Filter(
			order;
			ID = NID
		)

Set the edit form's DefaultMode: FormMode.Edit

The multiple look-up column's combo box's DefaultSelectedItems: Parent.Default   (this will load the original data)

Set the multiple look-up column's datacard's Update: DataCardValue16.SelectedItems

 

2)save the original data as a collection

ClearCollect(test;First( Filter( order; ID = NID ).posotions          //save the original data as a collection
Collect(test,{Id: PID;Value: LookUp(positions;ID = PID;toShow)}) // save the new data to the save collection
Patch(order;
LookUp( order; ID = NID );
{positions:test}
)

 Use the function of patch will not save the original data.

That's the reason why I use collection.

I think maybe you need to kown more about patch.

Here's a doc about if for your reference:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

 

Best regards,

Community Support Team _ Phoebe Liu

Community Support Team _ Phoebe Liu
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

2 REPLIES 2
v-yutliu-msft
Community Support
Community Support

Hi @Ascawath ,

Do you want to update a multiple look-up column?

If you want to use the original data, I suggest you two ways:

1)use edit form

Set the edit form's Item:

First(
		Filter(
			order;
			ID = NID
		)

Set the edit form's DefaultMode: FormMode.Edit

The multiple look-up column's combo box's DefaultSelectedItems: Parent.Default   (this will load the original data)

Set the multiple look-up column's datacard's Update: DataCardValue16.SelectedItems

 

2)save the original data as a collection

ClearCollect(test;First( Filter( order; ID = NID ).posotions          //save the original data as a collection
Collect(test,{Id: PID;Value: LookUp(positions;ID = PID;toShow)}) // save the new data to the save collection
Patch(order;
LookUp( order; ID = NID );
{positions:test}
)

 Use the function of patch will not save the original data.

That's the reason why I use collection.

I think maybe you need to kown more about patch.

Here's a doc about if for your reference:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

 

Best regards,

Community Support Team _ Phoebe Liu

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

Hi,

Thanks for your reply.
I took the second way.
I thought collect adds a new item to a collection and regarding to a table or list, collect would add this item directly to the list/table.

Thanks for your help

And kind regards

Helpful resources

Announcements
Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

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.

<
Users online (4,830)