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

Modifying CDS Field (Option Set) after button action (OnSelect)

Hello Power Apps Community!

 

It's the first time I'm using Forms in a Power App and I'm struggling a bit with a couple of things. However, there's one of them that I can't find a workaraound to it.

 

The DataSource is a custom CDS Entity (Expenses). It has a field called ExpenseStatus whose values come from an OptionSet (New, Registered). I want to be able to change the value of this field from a button in another screen (not the form screen). Is there a way I can do that?

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
PowerAppsDaniel
Level: Powered On

Re: Modifying CDS Field (Option Set) after button action (OnSelect)

Hey @v-yutliu-msft,

 

Thank you for your reply. It didn't work at first, but after a while I managed to get it right changing a few things:

 

// The Gallery.AllItems was collecting a lot of "garbage" that prevented the Patch from working right so I changed it to what the Items property in the Gallery itself was.
ClearCollect(data, Filter(Expenses, Employee = CurrentUser));
// A few changes to make it work: 
ForAll(data, Patch([@Expenses], LookUp([@Expenses], UniqueID = data[@prefix_uniqueid]), {ExpenseState: [@ExpenseStateOptionSet].Registered}));

 

Hope this helps anyone else too!

View solution in original post

6 REPLIES 6
Dual Super User
Dual Super User

Re: Modifying CDS Field (Option Set) after button action (OnSelect)

Hey @PowerAppsDaniel 

 

Can you share more details about this? Is this about the edit form to update an already existing item?

What is the Item property of the edit form?

On a different screen, you can sue the expression as:

Patch(DataSource, LookUp(DataSource, UniqueIdentifierColumn = Form1.Updates.UniqueIdentifierColumn), {ExpenseStatus: 'ExpenseStatus (DataSource)'.Registered})

This will save the value for the selected record in Edit Form. If this differs, please share the logical implementation of this so that we might be able to help you better.

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

PowerAppsDaniel
Level: Powered On

Re: Modifying CDS Field (Option Set) after button action (OnSelect)

Hey @yashag2255,

 

Thank your for the reply. More details about the app:

 

Relevant screens:

  • Form Screen - EditForm (DataSource = Expenses) with the fields that the user can edit (ExpenseStatus is not editable by the user). A button to submit the form.
  • Expenses List Screen - A Gallery Control to show the user's expenses. A button that triggers a flow. I want this button to change the ExpenseStatus field before triggering the Power Automate flow.

I tried your formula but it doesn't work. Feel free to ask for more details if needed.

Community Support Team
Community Support Team

Re: Modifying CDS Field (Option Set) after button action (OnSelect)

Hi @PowerAppsDaniel ,

Do you want to click button inside a gallery to update ExpenseStatus ?

Could you tell me is ExpenseStatus a custom option set?

If so, I've made a similar test for your reference:

1)my custom option set name is test123

entity name is testmanies

2)insert two buttons inside the gallery, one for updating data to New, one for updating data to  Registered.

Please click this in the gallery, then insert buttons, then the button will display in every item.

1230.PNG

 

3)set the new button's OnSelect:

Patch(testmanies,ThisItem,{'ExpenseStatus ':test123.New})

set the new button's Registered:

Patch(testmanies,ThisItem,{'ExpenseStatus ':test123.Registered})

 On your side, you should try:

Patch(Expenses,ThisItem,{'ExpenseStatus ':opetionsetname.New});
Patch(Expenses,ThisItem,{'ExpenseStatus ':opetionsetname.Registered})

12311.PNG

 

 

Best regards,

 

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.
PowerAppsDaniel
Level: Powered On

Re: Modifying CDS Field (Option Set) after button action (OnSelect)

Hi @v-yutliu-msft,

 

Thank you for your reply. I'll answer your questions below:

 

  • Do you want to click button inside a gallery to update ExpenseStatus?  No, the button is outside the gallery and has to change the ExpenseStatus to all the items that are (in that moment) in the gallery.
  • Could you tell me is ExpenseStatus a custom option set? Yes, ExpenseStatus is an OptionSet with two values currently (New, Registered).

I would basically need what you suggested, but for all the elements in the gallery. 

Community Support Team
Community Support Team

Re: Modifying CDS Field (Option Set) after button action (OnSelect)

Hi @PowerAppsDaniel ,

Do you want to use a button to change all the gallery's items' ExpenseStatus value?

If so, it means that you want to update multiple records at the same time.

Try this formula:

1)update to new value

ClearCollect(data,Gallery1.AllItems);
ForAll(data,Patch(Expenses,LookUp(Expenses,uniquefield=data[@uniquefiel]),{'ExpenseStatus ':opetionsetname.New}))

 2)update to  Registered value:

ClearCollect(data,Gallery1.AllItems);
ForAll(data,Patch(Expenses,LookUp(Expenses,uniquefiel=data[@uniquefiel]),{'ExpenseStatus ':opetionsetname.Registered}))

 Please replace the uniquefield and optionsetname with the names that you need.

 

Here's a doc about how to update multiple records at the same time:

https://powerapps.microsoft.com/en-us/blog/bulk-update-using-forall-and-patch/

 

 

 

Best regards,

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.
PowerAppsDaniel
Level: Powered On

Re: Modifying CDS Field (Option Set) after button action (OnSelect)

Hey @v-yutliu-msft,

 

Thank you for your reply. It didn't work at first, but after a while I managed to get it right changing a few things:

 

// The Gallery.AllItems was collecting a lot of "garbage" that prevented the Patch from working right so I changed it to what the Items property in the Gallery itself was.
ClearCollect(data, Filter(Expenses, Employee = CurrentUser));
// A few changes to make it work: 
ForAll(data, Patch([@Expenses], LookUp([@Expenses], UniqueID = data[@prefix_uniqueid]), {ExpenseState: [@ExpenseStateOptionSet].Registered}));

 

Hope this helps anyone else too!

View solution in original post

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (4,782)