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

Submits two forms possible due to Patch() Function

Hi.

 

I have an app in which we store data for possible projects. In this we have fields in which "Win Ratio" is added, client name etc etc.

 

My issue is that when I add a NEW (not when I edit existing) it adds a new form ONLY consisting the inserted Win Ratio. The Win Ratio DataCardValue has a Patch() function in the OnChange property as I need it to update so that I can calculate in another field. I suspect this is the issue, but do not know how to figure out how to solve this problem. I have added a screenshot below so that you can see the two newly added items in the gallery:

 

MultipleSubmitWhenNew1.JPG

 

These were added at the same time. The first ONLY contains the Win Ratio which I intended to add when I submitted the AAA client.

 

When I edit the Win Ratio field in the editform (New form) it gives the dots above, which shows how it is saving/updating:

 

MultipleSubmitWhenNew2.JPG

 

 

I have tried deleting and readding and manually writing the Patch again. The Patch() in the Onchange of the Win Ratio is:

 

Patch(Maintable_SPM, ThisItem,{'Win Ratio': Value(DataCardValue40.Text)})
20 REPLIES 20
gabibalaban
Level 8

Re: Submits two forms possible due to Patch() Function

If you want to write some new info into a collection / datasource using Patch you need to use something like:

 

PATCH(collection,defaults(collection), {item; item})

 

The code you've used refer only to an existing record.

 

To solve the problem, you can also use smthg like:

PATCH(collection, if (is_new_item,defaults(collection),thisitem), {item; item}).

 

AndersIskov
Level: Powered On

Re: Submits two forms possible due to Patch() Function

 @gabibalaban , thank you for the response!

 

Being new I am a bit confused with your formula, I made it like this, but it gives me an error:

 

Patch(Maintable_SPM, If(NewForm(Defaults(Maintable_SPM),ThisItem), {'Win Ratio': Datacardvalue40})

 

 

gabibalaban
Level 8

Re: Submits two forms possible due to Patch() Function

Sorry, now i saw that you are using FORM. Can you try with SubmitForm.

The PATCH function is nou usable in these circumstances.

AndersIskov
Level: Powered On

Re: Submits two forms possible due to Patch() Function

@gabibalaban

I think it already saves it the moment I enter a win ratio, that seems to be the issue. The screenshot in my first post shows how it is updating the form when I enter the win ratio
AndersIskov
Level: Powered On

Re: Submits two forms possible due to Patch() Function

The problem seems to arise when I use the Value(DataCardValue40.Text). In the Patch() function:

 

Patch(Maintable_SPM, ThisItem, {'Win Ratio': Value(DataCardValue40.Text)})

 

But I need to use Value(.Text) because otherwise it gives me an error:

 

"Server Response: A value most be provided for Item. ClientRequestID: xxxxxxxxxxxxxxxxxxxxxx"

AndersIskov
Level: Powered On

Re: Submits two forms possible due to Patch() Function

@gabibalaban @mdevaney @CarlosFigueira 

If any of you can help me.

 

I have now 100% found the problem. It is basically as my latest post suggest due to the fact that different fields have Patch() formulas in them.

 

Below I have a NEWFORM/EDITFORM in which I give the AccountName, Phase, Client Budget, Win Ratio and Duration in Days:

 

SubmittingError2.JPGSubmittingError1.JPG

 

 

When I finally submit, I find 5 new items in my gallery:

 

SubmittingError3.JPG

 

 

1. The correct form with all the data

2. Only containing the Phase

3. Only containing the Win Ratio

4. Only containing Client Budget

5. Only containing the duration in days

 

 

All of those fields each have a Patch() function so that the monthly average will be immediately calculated. The functions are:

 

 

FOR PHASE:         Patch(Maintable_SPM, ThisItem, {Phase: DropdownPhase.Selected.Phase})

FOR CLIENT BUDGET: Patch(Maintable_SPM, ThisItem,{'Client Budget': Value(ClientBudgetDataCardValue.Text)})

FOR WIN RATIO:    Patch(Maintable_SPM, ThisItem,{'Win Ratio': Value(WinRatioDataCardValue.Text)})

FOR DURATION IN DAYS: Patch(Maintable_SPM, ThisItem,{'Duration in Days': Value(DurationDaysDataCardValue.Text)})

 

 

I need to add the Value(XXXXX.Text) for the patch function, otherwise I get an error everytime I change the data in the form:

 

"A value must be provided for item"

 

EDIT: I should mention this does NOT happen when I EDIT an existing item.

Super User
Super User

Re: Submits two forms possible due to Patch() Function

The patch code you have there is ONLY for editing an existing item. To create a new you use:

 

Patch(SPList, Defaults(SPList), {Title: TextInput.Text, Column2: TextInput.Text})

 

You need something that looks to see if it is new or an edit (a variable or if statement) and use the code you have when it is an edit and the other when it is creating a new entry.

 

You are correct in that fact that you will have to use the Value(TextInput.Text) -- anytime you have a number column of any sort you will need to use that.

AndersIskov
Level: Powered On

Re: Submits two forms possible due to Patch() Function

@rebeccas 

Thank you for the response.

 

Can you guide me a little how I would integrate that into the current patch formula I have?

 

I am using an Excel Maintable. I assume that is not a problem?

 

If this is the patch function for the client budget, how do I integrate the patch function for a new form?:

 

Patch(Maintable_SPM, ThisItem,{'Client Budget': Value(ClientBudgetDataCardValue.Text)})

 

Super User
Super User

Re: Submits two forms possible due to Patch() Function

I normally do SharePoint list, not excel...I find it works better with PowerApps so I'm not sure about the differences there. Is this all going to one place or you have two different worksheets you are posting to?

 

Also, that Patch part you put above that you are using...did you split that out just to show here or that is what you are using because that can be combined to:

 

Patch(Maintable_SPM, ThisItem,
{Phase: DropdownPhase.Selected.Phase, 'Client Budget': Value(ClientBudgetDataCardValue.Text, 'Win Ratio': Value(WinRatioDataCardValue.Text), 'Duration in Days': Value(DurationdaysDataCardValue.Text)})

 

Only reason you would do it split is if you are using something besides the "Maintable_SPM"

 

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps 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

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,186)