cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Questionasking
Helper III
Helper III

Custom Patch Code, If Dropdown equals Completed then patch to different source if not SubmitForm

Hi,

 

I have a form app with a flow that once the user submits task it sends the data to another list (A Completed List), however it takes 10mins sometimes to move over, i figured i can make it work another way by using the patch and an If Statment, however my attempts at coding it are at a loss,

 

So Is it possible to have an button use OnSelect if a dropdown equals say "Completed" then rather than OnSubmit Patch to another source and if anything else then just submitform? and id like it to also delete the item after onsuccess.

 

Could someone post the example code i would need?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

@Questionasking 

Result working:

 

AppCompletedSample-898253-a.gif

 

 

Explanation (for the explanation it was tested with a real SharePoint List and found to be working - note that this actually differs a little bit from the attached msapp file at the bottom of this post):

 

Working SharePoint List Patch Example App (not provided as an msapp in the attachment - so see instead full explanation below, and possibly import attached msapp and adjust it using the below explanation if you want):

 

App has two Screens, Screen1 and Screen2 (Screen1 is most important - Screen2 is optional but if using exactly this specific example, both screens should be there in that case):

 

On Screen 1:

 

Screen1 OnVisible:

 

 

 

 

 

Refresh(Completed);ClearCollect(_SampleCollDef01,Split("Not Completed,Completed",","));Reset(Dropdown2);Reset(TextInput1);

 

 

 

 

In the above the most important part is just:

 

 

 

ClearCollect(_SampleCollDef01,Split("Not Completed,Completed",","));

 

 

 

the main purpose of this formula is to generate the wo options to select from, "Not Completed" and "Completed" for the Dropdown control for the main scenario that is the subject of your initial question.

 

 

Controls and other items present on Screen1:

 

One Gallery with Layout set to 'Title' on the right pane.

 

Presumes also one Data Source of SharePoint List, data source is called Completed in this example, associated with this App.

 

Gallery1 Items:

 

 

 

Completed

 

 

 

"Completed" here is referring to the specific name of the SharePoint List data source we created that was tested by us, and is not referring specifically to the name of the value of the Dropdown2 option of "Completed".

 

One Dropdown

 

Dropdown2 Items:

 

 

 

_SampleCollDef01

 

 

 

 

One TextInput

 

TextInput1 Default:

 

 

 

"Some Default Title"

 

 

 

 

One Button

 

Button1 OnSelect:

 

 

 

If(Dropdown2.Selected.Result = "Completed"
,
   Patch(
      Completed
      ,
      {Title:TextInput1.Text}
   )
,
   Navigate(Screen2)
)

 

 

 

The above checks if the dropdown value is "Completed" - if it is, performs the Patch to SharePoint List Data Source (which is actually named Completed in this case) using the Text Value present in TextInput1,
and if dropdown value is something else than "Completed" - then it will do something else - in this simple example, it will navigate to some other Screen.

 

 

 

 

On Screen 2:

 

One Label

 

Label1 Text:

 

 

 

"This screen being navigated to when Completed is not the current dropdown value."

 

 

 

 

One Button

 

Button3 OnSelect:

 

 

 

Navigate(Screen1)

 

 

 

 

 

 

Sample app and instructions to import the sample app to play with yourself: 

 

AppCompletedSample-898253-v1-coll.msapp

 

This sample app is different and does not match exactly the Explanation above. This is because this sample app does not use SharePoint List data source, but instead uses inline mock Collection -- so notice it uses Collect instead of Patch as well there - so use explanation above instead for that one with SharePoint List, and use msapp as starting point on conjunction with the explanation above. The graphic showing it working at very top of this post, in SharePoint List, uses the version tested with SharePoint List (not provided here as an msapp file attachment - only the provided Explanation above is associated with that working version we tested). The reason is so that you can play with it yourself using local mock Collection right away on import for easiest import and maximum portability.

 

In case you still do want to import the attached msapp file to play with the sample App yourself:

 

msapp import:

 

  1.  Navigate with your browser manually to this URL (or just click the following link): https://us.create.powerapps.com/studio/
  2.  Then, Click "Open" on the left side
  3.  Next, Click "Browse" on the right side
  4. Finally, select the msapp file from the window when prompted.
  5. Done

The attached msapp version  AppCompletedSample-898253-v1-coll.msapp differs slightly from the actual tested app that is subject to the graphic and full explanation above - here is a graphic of the msapp version of local collection version sample app as well in case, but notice that this app version differs slightly from the version used in Explanation and the graphic at the top (no msapp is included for version tested by us with SharePoint List - but full Explanation of all key formulas and Controls, included above. Also since the app versions are very similar, you can easily just import the attached msapp then change just a few formulas using the full Explanation above, for it to point to your specific SharePoint List and just use Explanation above to make the relevant changes).

 

AppCompletedSample-898253-b.gif

 

 

 

View solution in original post

1 REPLY 1

@Questionasking 

Result working:

 

AppCompletedSample-898253-a.gif

 

 

Explanation (for the explanation it was tested with a real SharePoint List and found to be working - note that this actually differs a little bit from the attached msapp file at the bottom of this post):

 

Working SharePoint List Patch Example App (not provided as an msapp in the attachment - so see instead full explanation below, and possibly import attached msapp and adjust it using the below explanation if you want):

 

App has two Screens, Screen1 and Screen2 (Screen1 is most important - Screen2 is optional but if using exactly this specific example, both screens should be there in that case):

 

On Screen 1:

 

Screen1 OnVisible:

 

 

 

 

 

Refresh(Completed);ClearCollect(_SampleCollDef01,Split("Not Completed,Completed",","));Reset(Dropdown2);Reset(TextInput1);

 

 

 

 

In the above the most important part is just:

 

 

 

ClearCollect(_SampleCollDef01,Split("Not Completed,Completed",","));

 

 

 

the main purpose of this formula is to generate the wo options to select from, "Not Completed" and "Completed" for the Dropdown control for the main scenario that is the subject of your initial question.

 

 

Controls and other items present on Screen1:

 

One Gallery with Layout set to 'Title' on the right pane.

 

Presumes also one Data Source of SharePoint List, data source is called Completed in this example, associated with this App.

 

Gallery1 Items:

 

 

 

Completed

 

 

 

"Completed" here is referring to the specific name of the SharePoint List data source we created that was tested by us, and is not referring specifically to the name of the value of the Dropdown2 option of "Completed".

 

One Dropdown

 

Dropdown2 Items:

 

 

 

_SampleCollDef01

 

 

 

 

One TextInput

 

TextInput1 Default:

 

 

 

"Some Default Title"

 

 

 

 

One Button

 

Button1 OnSelect:

 

 

 

If(Dropdown2.Selected.Result = "Completed"
,
   Patch(
      Completed
      ,
      {Title:TextInput1.Text}
   )
,
   Navigate(Screen2)
)

 

 

 

The above checks if the dropdown value is "Completed" - if it is, performs the Patch to SharePoint List Data Source (which is actually named Completed in this case) using the Text Value present in TextInput1,
and if dropdown value is something else than "Completed" - then it will do something else - in this simple example, it will navigate to some other Screen.

 

 

 

 

On Screen 2:

 

One Label

 

Label1 Text:

 

 

 

"This screen being navigated to when Completed is not the current dropdown value."

 

 

 

 

One Button

 

Button3 OnSelect:

 

 

 

Navigate(Screen1)

 

 

 

 

 

 

Sample app and instructions to import the sample app to play with yourself: 

 

AppCompletedSample-898253-v1-coll.msapp

 

This sample app is different and does not match exactly the Explanation above. This is because this sample app does not use SharePoint List data source, but instead uses inline mock Collection -- so notice it uses Collect instead of Patch as well there - so use explanation above instead for that one with SharePoint List, and use msapp as starting point on conjunction with the explanation above. The graphic showing it working at very top of this post, in SharePoint List, uses the version tested with SharePoint List (not provided here as an msapp file attachment - only the provided Explanation above is associated with that working version we tested). The reason is so that you can play with it yourself using local mock Collection right away on import for easiest import and maximum portability.

 

In case you still do want to import the attached msapp file to play with the sample App yourself:

 

msapp import:

 

  1.  Navigate with your browser manually to this URL (or just click the following link): https://us.create.powerapps.com/studio/
  2.  Then, Click "Open" on the left side
  3.  Next, Click "Browse" on the right side
  4. Finally, select the msapp file from the window when prompted.
  5. Done

The attached msapp version  AppCompletedSample-898253-v1-coll.msapp differs slightly from the actual tested app that is subject to the graphic and full explanation above - here is a graphic of the msapp version of local collection version sample app as well in case, but notice that this app version differs slightly from the version used in Explanation and the graphic at the top (no msapp is included for version tested by us with SharePoint List - but full Explanation of all key formulas and Controls, included above. Also since the app versions are very similar, you can easily just import the attached msapp then change just a few formulas using the full Explanation above, for it to point to your specific SharePoint List and just use Explanation above to make the relevant changes).

 

AppCompletedSample-898253-b.gif

 

 

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (1,648)