cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MikeLockwood
Level 8

SharePoint Custom Form + Submit + Patch

So a pretty simple concept here.  I have Table A that has data and Table B that has data, lets say Procurement data and invoices.  Just in-case it matters the data is relational but I'm not using lookup fields as they default to the first item which I dont want.  The Invoice page has a custom form that lets you select the PO Number from Table A, this form then allows you to add an invoice amount and save it.  I want to not only save it using the SharePoint button but update the remaining balance value in Table A using a patch command.  Now i have this working using the below code on the SharePointIntegration.OnSave command.  The problem is the Patch command works fine and complete but if the SubmitForm has errors it stops there.  Then if you correct the issue and submit the Patch runs again.  I have tried to run the SubmitForm first and then do the patch but it does not work, it save the record but the Patch does not run.

 

Looking for thoughts.

 

If(
    SharePointFormMode = "Create",
    If(
        Value(DataCardValue23.Text) <= 0,
        Patch(
            Procurement,
            {ID: Value(POID.Text)},
            {
                Status: "Paid",
                Balance_x0020_Remaining: Value(DataCardValue23.Text)
            }
        );
        SubmitForm(CreateForm),
         Patch(
            Procurement,
            {ID: Value(POID.Text)},
            {Balance_x0020_Remaining: Value(DataCardValue23.Text)}
        );
         SubmitForm(CreateForm)
    ),
    SharePointFormMode = "Edit",
    If(
        Value(DataCardValue23.Text) <= 0,
        Patch(
            Procurement,
            {ID: Value(POID.Text)},
            {
                Status: "Paid",
                Balance_x0020_Remaining: Value(DataCardValue23.Text)
            }
        );
        SubmitForm(EditForm),
        Patch(
            Procurement,
            {ID: Value(POID.Text)},
            {Balance_x0020_Remaining: Value(DataCardValue23.Text)}
        );
        SubmitForm(EditForm)
    )
)
Thanks,
Mike L.
1 REPLY 1
nickduxfield
Level 8

Re: SharePoint Custom Form + Submit + Patch

I can possibly help you on this as I have had to solve many of these issues in my APPs.

 

Firstly, although it takes work.

Its a good idea to do the following to be clear.

  1. Rename all the DataCards to relevant names
    1. DataCard_Title
    2. DataCardKey_Title
    3. DataCardValue_Title
  2. Setup a simple ContextVariable at each step in the code.
    1. UpdateContext({MyNotes:"Onselect/SubmitForm/})
    2. UpdateContext({MyNotes:"Onselect/SubmitForm/OnSuccess/})
    3. UpdateContext({MyNotes:"Onselect/SubmitForm/OnSuccess/Patch(1)})
    4. UpdateContext({MyNotes:"Onselect/SubmitForm/OnSuccess/Patch(1)/End})
  3. Then place a label on the screen in light red, then a note on each other screen that points to the master label.

Run the routine, then look for the last message on the MyNotes notification.

 

------------------------

 

Further ideas:

Use Switch so you can easily work out the logic, and add more later as you need functionality.

 

 

Switch(SharePointFormMode,

"Create",

   Switch(Value(DataCardValue23.Text),

      <= 0, Patch( Procurement, {ID: Value(POID.Text)}, { Status: "Paid", Balance_x0020_Remaining: Value(DataCardValue23.Text) } ); SubmitForm(CreateForm),

      Patch( Procurement, {ID: Value(POID.Text)}, {Balance_x0020_Remaining: Value(DataCardValue23.Text)} ); SubmitForm(CreateForm) ),

"Edit",

   Switch(Value(DataCardValue23.Text),

      <= 0,

      Patch( Procurement, {ID: Value(POID.Text)}, { Status: "Paid", Balance_x0020_Remaining: Value(DataCardValue23.Text) } ); SubmitForm(EditForm), Patch( Procurement, {ID: Value(POID.Text)}, {Balance_x0020_Remaining: Value(DataCardValue23.Text)} ); SubmitForm(EditForm) )

)

 

 

 

 

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,137)