cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dineshks
Level: Powered On

Patch is not working in custom button OnSelect. Please advise

Hi Guys,

 

I want to set a dropdown when I click a custom button "Submit".  I did below in the button OnSelect and it was worked fine earlier..But I don't know why it is not working today..

 

Is there any update happened in PowerApps?.

 

Kindly advise if I am missing something..

 

SubmitForm(SharePointForm1);Patch('My List Name',First(Filter('My List Name',ID=SharePointForm1.LastSubmit.ID)),{"Request_x0020_Version": First(Filter(DataCardValue17.SelectedItems,Value = "Final"))})

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
tommyly
Level 8

Re: Patch is not working in custom button OnSelect. Please advise

My usual disclaimer is that there are always several ways to approach a solution. Here is one:

 

Introduce a local boolean-variable called varSubmitForApproval (you could name it anything, really) in the screen's OnVisible event. This instantiates the variable so that the app knows the datatype: true/false.

UpdateContext({varSubmitForApproval:false})

In your form's DataCard#.Update property, it should currently be equal myDropDown.Selected.Value. You can change it to something like this:

If(varSubmitForApproval=true, "Final", myDropDown.Selected.Value)

or if you want to be really nerdy, you can omit the "=true" part:

If(varSubmitForApproval, "Final", myDropDown.Selected.Value)

Since varSubmitForApproval is defined as "false" (in your Screen.OnVisible event), it will--by default--reference your dropdown list. Here's the catch. In your SubmitForApproval button, have this in the OnSelect event:

UpdateContext({varSubmitForApproval:true});
SubmitForm(SharePointForm1)

And then in your SharePointForm1.OnSuccess event, have the local variable reset itself with this syntax (and you may want to put the same syntax in the OnFailure event, just in case...):

UpdateContext({varSubmitForApproval:false})

 

The net result is that your form will always accept the dropDown value; however, when you click on the Submit-For-Approval button, it will switch the local variable to true. And then the form takes instruction in the DataCard#.Update property (If-Statement) to override the dropdown selection with "Final".

In this way, you avoid having to patch anything at all. Metaphorically, you give the parcel to the mailman before he leaves the building and avoid having to send your poor secretary to the post office to reconcile. I hope that helps, or at least gives you some avenue for further research.

View solution in original post

4 REPLIES 4
tommyly
Level 8

Re: Patch is not working in custom button OnSelect. Please advise

SubmitForm(SharePointForm1);
Patch('My List Name',
  First(Filter('My List Name',ID=SharePointForm1.LastSubmit.ID)),
{
"Request_x0020_Version": First(Filter(DataCardValue17.SelectedItems,Value = "Final"))
}
)

At first glance, it seems confusing what you are trying to do. Let me try to summarize what I initially see you doing here:

  • You have a list called 'My List Name'
  • You would like to take the previously submitted record (i.e. .LastSubmit)...
  • And in that previously-submitted record, you'd like to update the field Request_x0020_version with...
  • The first item in a comboBox whose field/column Value matches "Final"

Here are some inconsistencies I see:

  • First off, Request_x0020_Version should not have quotes around it. I'm not sure if having quotes is allowed (*shrug*); never tried, but you should be able to drop them
  • There is an inconsistency with the way you use LastSubmit here:
    1. Let's imagine you were testing your PowerApps form and simply using the syntax of "SubmitForm(SharePointForm1)". Simple. And yay, it works!
    2. And then moments later, you add "Patch('My List Name',First(Filter('My List Name',ID=SharePointForm1.LastSubmit.ID))..." (and the rest of the code). Yay, it works! But note that it's only because of your testing in Step1 that has provided context (during that session of your app) to the meaning of "LastSubmit"
    3. If you were to restart your app (do a clean restart with a new app session), your Submit button will fail because Step1 never happens during that new session. It's referencing "LastSubmit" but it doesn't know what was previously submitted; that said, once you manage to submit something, then your Submit button will start working.
  • Lastly, I'm not sure what you are trying to do by setting a field to an item in a comboBox with the value of "Final". SelectedItems means what it infers... the items that which a user has selected within a comboBox. So if the user does not select the comboBox item of "Final", then your Patch command would append a blank to the Request_x0020_Version field/column. If that's what's intended, then that's fine. It just seems like a roundabout way of doing so

More context to your project/objective might be helpful in answering your question, but if I were a betting man, I would say your problem has to do with LastSubmit. If this is the case, then you have to relook at the design process of your form.

 

 

dineshks
Level: Powered On

Re: Patch is not working in custom button OnSelect. Please advise

Thank you so much for your time...

 

I am using PowerApps SharePointForm1 opened using "Customize" from "My List Name"

 

1) I have a choice field in the SharePoint list called "Request Version" and it has two items "Draft" and "Final". I set the "Draft" as default in the choice field, because I want to set the field as "Draft" when user clicks on "Save" (OOTB) button

2) I have one custom button in the form called "Submit for Approval" and I want to set the dropdown value to "Final" when I hit this custom button from the add new item mode. 

 

So tried to update the value to "Final" using Patch and LastSubmit.  Please advise how can I do that..

 

Thanks in Advance.

 

tommyly
Level 8

Re: Patch is not working in custom button OnSelect. Please advise

My usual disclaimer is that there are always several ways to approach a solution. Here is one:

 

Introduce a local boolean-variable called varSubmitForApproval (you could name it anything, really) in the screen's OnVisible event. This instantiates the variable so that the app knows the datatype: true/false.

UpdateContext({varSubmitForApproval:false})

In your form's DataCard#.Update property, it should currently be equal myDropDown.Selected.Value. You can change it to something like this:

If(varSubmitForApproval=true, "Final", myDropDown.Selected.Value)

or if you want to be really nerdy, you can omit the "=true" part:

If(varSubmitForApproval, "Final", myDropDown.Selected.Value)

Since varSubmitForApproval is defined as "false" (in your Screen.OnVisible event), it will--by default--reference your dropdown list. Here's the catch. In your SubmitForApproval button, have this in the OnSelect event:

UpdateContext({varSubmitForApproval:true});
SubmitForm(SharePointForm1)

And then in your SharePointForm1.OnSuccess event, have the local variable reset itself with this syntax (and you may want to put the same syntax in the OnFailure event, just in case...):

UpdateContext({varSubmitForApproval:false})

 

The net result is that your form will always accept the dropDown value; however, when you click on the Submit-For-Approval button, it will switch the local variable to true. And then the form takes instruction in the DataCard#.Update property (If-Statement) to override the dropdown selection with "Final".

In this way, you avoid having to patch anything at all. Metaphorically, you give the parcel to the mailman before he leaves the building and avoid having to send your poor secretary to the post office to reconcile. I hope that helps, or at least gives you some avenue for further research.

View solution in original post

Highlighted
dineshks
Level: Powered On

Re: Patch is not working in custom button OnSelect. Please advise

Thank you so much!.

 

I did it in the DataCard#.Update property,

 

If(varSubmitForApproval, {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:-1,Value:"Final"},
DataCardValue17.Selected)

 

It is worked as expected. Thanks.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,018)