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.
Solved! Go to Solution.
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:
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
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:
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
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?
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.
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?
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.
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" } } )
Hi FacundoGorla ,
Its worked like a charm , thanks for posting this solution .
Regards,
Aarthi
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.
User | Count |
---|---|
205 | |
70 | |
49 | |
49 | |
20 |
User | Count |
---|---|
252 | |
124 | |
84 | |
76 | |
73 |