cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
FlyingTuga
New Member

Updating form field with button

Hi,

 

I am a PowerApps beginner and trying to create an app a somehow basic app.

 

I am using a SharePoint list as data source, and I am using a EditForm. I want to be able to update fields when I click a button (onSelect) and save it to SharePoint. I have seen several examples, though I don't seem to get it to work.

 

I am looking for:

 

  1. Have a button that updates the "Issue Status " field to "Resolved" and sets another field "Resolution date" with the current date;
  2. Another button labeled "Take Ownership" that updates the field "Owner" to the current user (type Person in SharePoint).

 

At this point I haven't even been able to update a simple basic text field with new text like "Test" at a click of a button.

 

I've seen examples that use the function PATCH, others that create a global variable and set the dropdown list to the variable, and a few other solutions, though I am not able to either update the field on the screen or update it on sharepoint. Any help would be appreciated.

 

Thanks

2 REPLIES 2
mdevaney
Super User
Super User

@FlyingTuga 

Here's my take on your two questions:

 

1.  Put this code in the OnSelect property of a button within your form to PATCH the status and resolution date.  My assumption here is Issue Status is a Choices field in SharePoint.  Replace the datasource name with your own. 

 

Patch(
    your_datasource_name,
    ID = ThisItem.ID,
    {'Issue Status':  {Value: "Resolved"}, 'Resolution date': Today()}
);

 

2.  Put this code in the OnSelect property of a button within your form to PATCH the current user into the Owner field.   Replace the datasource name with your own.

 

Patch(
    your_datasource_name,
    ID = ThisItem.ID,
    {
    Owner: 
        {
        '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
        Claims:"i:0#.f|membership|" & User().Email,
        Department:"",
        DisplayName: User().FullName,
        Email: User().Email,
        JobTitle:"",
        Picture:""
        }
    }
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Thank you @mdevaney, this worked for me with a tweak

 

I had to change slightly the code 

 

Patch(
IssuesTest,
First(Filter(IssuesTest,ID=BrowseGallery1.Selected.ID)),
{'Status':{Value:"Resolved"},'Resolved on':Today()}
);

 

 

The ThisItem.ID was not working, I guess because the button is not within the form. Am I doing something wrong? I don't seem to be able to add a button within the form. I've also copied the First(Filter( from another post. Is this the most clean way to do it?

 

Thanks

 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PWREduCon768x460.png

Join us at PWR EduCon - A Power Platform Conference

Learn from the top Power BI, Power Apps, Power Automate & Power Virtual Agents experts!

Top Solution Authors
Top Kudoed Authors
Users online (3,159)