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

How to Save Choice field value using UpdateIf/Patch functions

Hi,

 

I have one button on click of it I would like to save choice field value. I have tried both the UpdateIf and Patch functions but not working.

 

Code of UpdateIf:

UpdateIf(Leaves,ID=ThisItem.ID,{Status:"Approved"})

Error:

"The type Text is invalid for column 'Status'. Record expected. The function 'UpdateIf' has some invalid arguments."

 

Code of Patch:

Patch(Leaves,Defaults(Leaves),{Status:"Approved"})

Error:

"The type of this argument 'Status' does not match the expected type 'Record'. Found type 'Text'. The function 'Patch' has some invalid arguments."

 

Please guide me for save choice field value.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: How to Save Choice field value using UpdateIf/Patch functions

Hi @SPDevOne,

 

To patch a Choice field, we need follow the way to patch a lookup field:

How to patch a SharePoint Lookup Column

As choice field is also a lookup type.

For the data field

'@odata.type', value should be: "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",

For the Id field (number type), it depends which choice you would like to patch, the pre-defined choices are marked from 0, 1, 2 and so on for this field,

For Value part, which is the choice value

For example, if we add a choice field, set its value to 

Red,  

Blue

Green

The corresponding Id should be:

Red->0

Blue->1

Green->2

So to patch a Choice field, the formula should be:

Patch('Testing list',
   Defaults('Testing list'),
{choice:
 {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
   Id:1,
  Value:"Enter Choice #2"}
 }
)

See the screenshots:

10.PNG

 

Adding some more information:

For your situation, I think the status should be the choice field, so basically the formula should be:

Patch(Leaves,
         Defaults(Leaves),
        {Status:
            {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
   Id:0,
  Value:"Approved"}
         }
   )

Please post back if you need any further assistance.

 

Regards

Michael Shao

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

Re: How to Save Choice field value using UpdateIf/Patch functions

Hi @SPDevOne,

 

To patch a Choice field, we need follow the way to patch a lookup field:

How to patch a SharePoint Lookup Column

As choice field is also a lookup type.

For the data field

'@odata.type', value should be: "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",

For the Id field (number type), it depends which choice you would like to patch, the pre-defined choices are marked from 0, 1, 2 and so on for this field,

For Value part, which is the choice value

For example, if we add a choice field, set its value to 

Red,  

Blue

Green

The corresponding Id should be:

Red->0

Blue->1

Green->2

So to patch a Choice field, the formula should be:

Patch('Testing list',
   Defaults('Testing list'),
{choice:
 {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
   Id:1,
  Value:"Enter Choice #2"}
 }
)

See the screenshots:

10.PNG

 

Adding some more information:

For your situation, I think the status should be the choice field, so basically the formula should be:

Patch(Leaves,
         Defaults(Leaves),
        {Status:
            {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
   Id:0,
  Value:"Approved"}
         }
   )

Please post back if you need any further assistance.

 

Regards

Michael Shao

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.
Anonymous
Not applicable

Re: How to Save Choice field value using UpdateIf/Patch functions

I tried this solution with a button to mark a Drop Down Status field as "Complete". I am getting an error message "Title: Field Required"

 

Patch('Store Task Template',
   Defaults('Store Task Template'),
{Status:
 {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
   Id:2,
  Value:"Complete"}
 }
)

My list is "Store Task Template" the drop down field is "Status'. Any idea?

 

 

BrandonMurray
Level: Powered On

Re: How to Save Choice field value using UpdateIf/Patch functions

So... I can do this, but I'd really like some acknowledgement from the PowerApps dev team to the effect of, "This is AWFUL and we have plans to make this experience better..."

 

I should NOT have to do this when I want to use a button to set a Yes/No column in SharePoint with a PowerApps form.

HN
Level: Powered On

Re: How to Save Choice field value using UpdateIf/Patch functions

 i want to add a value in field name staus of type chioce on select the button i have an error title field required by using the formula you give in above post

Daniel_Pipe
Level: Powered On

Re: How to Save Choice field value using UpdateIf/Patch functions

This is SO CLOSE to what I need HOWEVER it creates a NEW RECORD in the sharepoint list.... I want to modify an existing record.... any ideas?

Daniel_Pipe
Level: Powered On

Re: How to Save Choice field value using UpdateIf/Patch functions

I finally worked out how to use a button in powerapps to update a choice field of an existing record:

 

Patch('<sharepointlist>',First(Filter('<sharepointlist>',ID = Gallery.Selected.ID)),{Status:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:4,Value:"Closed"}}); Navigate(<browsescreen>,ScreenTransition.Cover)

 

Replace <sharepointlist> with your correct sharepoint list name

Replace Id:4 and "Closed" with the 'choice'. In my case the 4th option in my dropdown is "Closed"

Replace <browsescreen> with whichever screen you want the user to be taken to next.

 

Hope that helps someone.

Highlighted
Vandkunst
Level: Powered On

Re: How to Save Choice field value using UpdateIf/Patch functions

@v-micsh-msft 

Thanks for the solution. It worked a charm for me Smiley Happy

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Tomorrow, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 225 members 3,996 guests
Please welcome our newest community members: