Forum Discussion
How to Update a Field through a button's OnSelect Event
I would need to build a sharepoint list and powerapp to test this, but what I would try is setting the value of the variable to the actual record that the dropdown in looking for, e.g.
Set(varStatus, Lookup(Status, Value = "Started"))
Let me know if trying something like this works and if not I will run up a test app for you.
Hey Peter,
I gave that a try and it appears to be the wrong syntax...tried various versions and recheck field and control names. If you are able to get a working version it would be very appreciated.
Suggested Form:
- Task (Title) Field - Text, Required
- Description Field - Plain Text, Multi-line
- Status Field - Choice, Required, "Not Started" (Default), "Started", "Complete"
- Due Date Field - Date, Required
- Link Field - Link or Picture set to URL
- Assignee Field - Name/Group, Required
- Button - "Mark Completed" Action: Changes Status Field to "Complete"
I tried to attach a template file, but it's not allowed here. PM me if you want me to email it.
- DeletedDec 16, 2017
On another app, I got the same error:
"An entry is required or has an invalid value. Please correct and try again."
In this case, I didn't have an ID field on the form. In this case, I had a Title field displayed as read-only. It was a required field, but I didn't create new items using this form, so I needed this field to be read-only. When I flipped it back to editable, the error went away. So my workaround was to change the visible property to hide the field and to display the Text of that field using a Label control. All is well in my form universe again.
- DeletedDec 13, 2017
Thanks Peter,
I tried substituting the Lookup for the Filter and could not resolve the syntax errors. I'm good for now. I'm pretty happy with the progress over a couple days in learning this from scratch.
- Peter McDonaldDec 12, 2017Brass Contributor
Good to see you found a working solution, just an FYI on your code you might be able to replace the First(Filter('Store Task Template',ID=SharePointIntegration.SelectedListItemID)) with Lookup('Store Task Template',ID=SharePointIntegration.SelectedListItemID) which is essentially the same thing but easier to follow.
https://docs.microsoft.com/en-us/powerapps/functions/function-filter-lookup
Nice work!
- DeletedDec 12, 2017
I was getting a nasty error on submit with the last solution: "An entry is required or has an invalid value. Please correct and try again." If you click on Submit again, the error goes away.
Others have discovered that this error is caused by having the SharePoint List ID field on the form. I removed it and it went away. However I need to access the ID to use Patch. So I dug and found I can get the ID from the SharePointIntegration Object as the property SelectedListItemID.
Works and no submit error message.
Patch('Store Task Template', First(Filter('Store Task Template',ID=SharePointIntegration.SelectedListItemID)), { Status:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Value:"Complete", Id:1 } } )
- DeletedDec 12, 2017
I have a working solution. I don't know if it's the best solution.
The OnSelect code for the button is:
Patch('Store Task Template', First(Filter('Store Task Template',ID=Value(IDValue.Text))), { Status:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Value:"Complete", Id:1 } } )
One thing I like is that it updates the current item whether in edit more or display mode. That will save mouseclicks for the end user who just wants to mark a task as done.
I would like to know how I can use the Filter to get the current item without having to look up the ID from a control as I did.