cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Rana1
Frequent Visitor

How to update Sharepoint list item when a form button is clicked

Hi,

 

I'm new to powerapps and I'm designing a leave request form and a flow based on a Sharepoint list.

I desgined the form by clicking PowerApps->Customize forms

 

Below are the requirements

1. Save the form data to SP list when the user clicks the "Save" button and update the Sharepoint List Column "Status" to "Draft"

2. Save the form data to SP list when the user clicks the "Submit" button and update the Sharepoint List Column "Status" to "Submitted"

3. Update the Sharepoint List Column "Status" to "Cancelled" when the user clicks the "Cancel" button.

 

The user may save the form data first and later come and submit it for approval.

 

I tried the patch function for the Cancel button, but it gives an error

Patch.PNG

 

Could someone help me on how to achieve the above three requriements.

 

Form.PNG

5 REPLIES 5
eka24
Super User
Super User

Try:

Patch('Leave Request', First( Filter('Leave Request', Title = TitleDataCardValue.Text ) ),

{ Status:"Cancelled"})

 

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

v-yutliu-msft
Community Support
Community Support

Hi @Rana1 ,

Could you tell me

1)the "Status" field's data type?

2)the choices of "Status" field, are they: "Draft", "Submitted" and "Cancelled"?
I assume that this field is a choice field.

If so, try this:

1)set save button's OnSelect:

SubmitForm(Formname);
Patch(listname,SharePointIntegration.Selected,{Status:{Value:"Draft"}})
//please replace with your formname, listname

2)set submit button's OnSelect:

 

SubmitForm(Formname);
Patch(listname,SharePointIntegration.Selected,{Status:{Value:"Submitted"}})
//please replace with your formname, listname

 

3)set cancel button's OnSelect:

Patch(listname,SharePointIntegration.Selected,{Status:{Value:"Cancelled"}})

 

Please notice that

1)you need to use {Value:...} to update a choice field.

2)you need to use SharePointIntegration.Selected to represent the selected item of this list.

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yutliu-msft ,

 

Thanks for your reply.

 

1. My "Status" field is a single line text field. 

2. The choices for the field are Draft,Pending Approval,Approved,Rejected and Cancelled. 

 

Your suggestion did work for Save and Cancel buttons.

 

For the Submit button I have the  requirement  to update the Status as "Pending Approval" when the user clicks Submit button. This worked when the user first saves the form and comes back and submits it. But the Status didn't update when a user Submitted a new form directly without saving. Is there a way to update the Status when the user directly Submits the form?

 

I used the below formula :

 

SubmitForm(SharePointForm1);Patch('Leave Request',SharePointIntegration.Selected,{Title:"Click Here",Status:"Submitted"});RequestHide()

 

Regards,

Rana1

Rana1
Frequent Visitor

Hi @eka24 ,

 

Your solution too worked for the "Cancelled " status and thanks for that. But I faced the same issue here also as the Status didn't update for newly created items when the form was submitted directly without saving. The Status updated correctly when a user opened a saved item and clicked Submit button. 

 

I used the below formula for the Submit button .

 

SubmitForm(SharePointForm1);Patch('Leave Request',First(Filter('Leave Request',Title=DataCardValue1.Text)),{Status:"Submitted"});RequestHide()

 

I guess the issue is "Title " field doesn't returns a value as  record is created for the first time. But this works once a record it created , because a value is returned for the Title.

 

Any idea how I can achieve this for newly created items. 

 

regards,

Rana1

@Rana1 Did you ever find a solution to this issue for newly created items?

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,597)