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

Submit and patch tables

I am submiting a form and patch two or more table on Button click event. But now its only do the submit part of code and succesffully the a table but patch is failed for another table. I want it should updates all table if no error occurs or otherwise should warn of fails. how can we achive that.  your valuable suggestion would highly appriciated.

 

for your reference, I am using this code sumbmit 

SubmitForm(frm_service);Patch('[gis].[app_service]',Defaults('[gis].[app_service]'),{appID:ComboBox4_appname.Selected.appID,serviceID:frm_service.LastSubmit.serviceID})

 

1 ACCEPTED SOLUTION

Accepted Solutions
mr-dang
Level 10

Re: Submit and patch tables

@mr-dang wrote:

 

For more reading on dialogs, please see these resources:

 

@sanrajbhar,

 

You can use the links above for instructions on how to make a pop-up dialog message.

 

The easier way to solve your problem would be to disable the submit button.

  1. Every control has a DisplayMode property.
  2. DisplayMode has 3 different modes: Edit, View, Disabled
  3. You can use a condition to change the mode. In your case, you want the button to be disabled when either of the comboboxes are empty.

    Button.DisplayMode:

    If(IsEmpty(ComboBox1.SelectedItems) || IsEmpty(ComboBox2.SelectedItems), DisplayMode.Disabled, DisplayMode.Edit )
    This means, "If ComboBox1 or ComboBox2 is empty, then disable the button, otherwise, allow the user to click the button."

  4. To show your user why they can't click the button, you can change the button's tooltip.
    Button.Tooltip:
    
    If(Button.DisplayMode=DisplayMode.Disabled, 
        "Please select a choice from each ComboBox.",
        "Submit this form"
    )

I attached a zip containing the app file that has this behavior.

Microsoft Employee
@8bitclassroom

View solution in original post

10 REPLIES 10
mr-dang
Level 10

Re: Submit and patch tables

Hi @sanrajbhar,

If I understand correctly:

  • You have a form that you submit, frm_service
  • But in addition to submitting the form, you also perform a Patch()
  • Patch() saves information based on the last record submitted by the form

 

Currently, the button with your formula looks like this:

 

SubmitForm(frm_service);

Patch('[gis].[app_service]',Defaults('[gis].[app_service]'),
    {appID:ComboBox4_appname.Selected.appID,
        serviceID:frm_service.LastSubmit.serviceID
    }
)

 

 

You can find more information on the error of the Patch by using the Errors function:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-errors

 

In your case, set a data table or gallery to:

Errors('[gis].[app_service]')

and it will show all the errors from the specified table.

 

My guess is that frm_service.LastSubmit is not showing up properly so the Patch is not going through.

 

I would set a label to:

frm_service.LastSubmit.serviceID

and see what appears.

 

Then the next step that you can try is to move the Patch formula to the OnSuccess property of the frm_service form. It might give it more time for the LastSubmit to populate and be successful.

 

Let me know how it goes.

 

Mr. Dang

 

 

___________________

Microsoft Employee
@8bitclassroom
sanrajbhar
Level: Powered On

Re: Submit and patch tables

Thanks for such wonderful reply. the above formula in my post above works well.  But unfortunately FormSubmit works and patch fails.(I know why this patch fails) So I want it to work like  - Both FrmSumbit and Patch should works.  if any of them fails, it should fails with proper massage warning

 

 

mr-dang
Level 10

Re: Submit and patch tables

I think I understand better now:

  • You want a way to notify the user if either the SubmitForm or the Patch fails

 

In this case, I would still use the Errors function. Extract the attached .msapp sample app file from the zip for more information on how to execute it.

 

  1. Insert a toggle. It has a Default property that determines if it is on or off. So we can make it listen for if there are any Errors in saving to your tables:
    !IsEmpty(Errors('[gis].[app_service]'))
    This means, "If the errors for your table are NOT empty, switch on, otherwise stay off."

  2. Make the toggle switch a variable to true. The variable will be used to show/hide a dialog to your user.
    Toggle.OnCheck:
    
    Set(showErrorMessage,true)
  3. Insert a label and type the warning you want to give your users if there is a failure in writing. Make it visible depending on the variable you just made.
    Label.Visible:
    showErrorMessage
  4. Make the warning label dismiss itself if the user clicks it.
    Label.OnSelect: 
    Set(showErrorMessage,false)

 

For more reading on dialogs, please see these resources:

 

Mr. Dang

 

_____________________

Microsoft Employee
@8bitclassroom
sanrajbhar
Level: Powered On

Re: Submit and patch tables

Apolgies..! as I am not able to convey my thoughts. sorry for that.

 

I Just need simple solution - i have a form and two comboxbox1 and combox2. these ComboxBoxes should not blank. User need to prompt to fill it if clicked on sumbit button.So Sumit button should tell user to fill ComboxBoxes if blank or No choice selected. if both of comboxes filled should do Sumbit action.

mr-dang
Level 10

Re: Submit and patch tables

Ah okay, I think I get it now:

  • You have two comboboxes
  • If either of them are blank, you want the Submit button to warn them
  • If they are not blank, go ahead and submit the form and patch

 

This is an exercise in conditions. There's a few ways to go about this:

  1. Disable the button unless both comboboxes are not empty/blank.
  2. Show a pop up dialog if a user attempts to submit but either of the boxes are blank.

 

Which one would you prefer?

Microsoft Employee
@8bitclassroom
sanrajbhar
Level: Powered On

Re: Submit and patch tables

Exactly..! Sorry mr. Dang for troubling you.  I am new to powerapps.

 

I will prefer showing  "Pop -up" Dialogue. but same keen to know the "Disable Sumbit Button unless both combox populated"

 

Thank you very much for your time and Help.

Meneghino
Level 10

Re: Submit and patch tables

Hi @sanrajbhar

 

@mr-dang's suggestion is excellent.  In addition to disabling and in alternative to pop-up you could just consider colouring the border of neede inputs red until filled or something like that.

 

However, I would like to suggest an alternative approach: leveraging the possibilities of calling stored procedures from PowerApps via Flow.  See here for references:

https://powerapps.microsoft.com/en-us/blog/return-an-array-from-flow-to-powerapps-response-method/

https://baizini-it.com/blog/index.php/2018/05/10/powerapps-concurrently-returning-variables-and-mult...

 

This solution will be much more robust and can be treated as a transaction by SQL Server, so that if one part fails for some reason then all is rolled back.  Please let me know if you are interested in more details.

sanrajbhar
Level: Powered On

Re: Submit and patch tables

Yes. your apprach seems good for when dealing with SQL server table. would like to know more about it. thanks

Meneghino
Level 10

Re: Submit and patch tables

Scenario: you create a record in TableA with inputs a, b, c then using the Id of the newly created record need to create a record in TableB with inputs d, e, f.

 

How-to:

1) In SQL Server create a stored procedure with inputs a,b,c,d,e,f that will do the above and return a variable with the status and/or the created record(s)

2) In Flow create a flow that will elicit a,b,c,d,e,f from PowerApps, execute the stored procedure and return the result to PowerApps

3) In PowerApps, connect the flow to your save button using Set(MyResult, MyFlow(a,b,c,d,e,f)) and then use MyResult to give feedback to the user and/or update the data displayed

 

Please let me know if the above makes sense and which steps (if any) need clarification

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
Users Online
Currently online: 131 members 5,045 guests
Please welcome our newest community members: