cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SPDevOne Helper I
Helper I

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

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.

View solution in original post

8 REPLIES 8
Community Support
Community Support

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.

View solution in original post

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?

 

 

Highlighted
BrandonMurray Advocate I
Advocate I

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 Helper I
Helper I

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 Advocate I
Advocate I

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 Advocate I
Advocate I

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.

Vandkunst
Frequent Visitor

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

@v-micsh-msft 

Thanks for the solution. It worked a charm for me 🙂

FacundoGorla Resolver I
Resolver I

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

Hi! hope you can answer this, just tried and your solution worked.

 

But I can´t understand the ID part, if I'm telling it to set the value in "Value: " why do I have to select an ID to tell wich option do I want.

 

I tried leaving the ID:1 and I can change the value of the data in that column of a single element to the value I want.

Just can't understad what does ID does. Heres the Code:

 

pdateIf(
    'Proyecto Facu';
    ID = Gallery1.Selected.ID;
    {
        Disponibilidad: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference";
            ID: 1;
            Value: "Libre"
        }
    }
)

Helpful resources

Announcements
secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Top Solution Authors
Top Kudoed Authors
Users online (7,704)