cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ClassyMustard
New Member

Duplicate entries on Patch() using ForAll()

Hi all,

 

Great community here, it's helped me a LOT solving some encountered issues...but this one has me stumped.

 

I am creating a simple purchase order requisition app for my organization. The user simply hits a button and it navigates to the "New PO" screen. The button sets up a form and collection to use by the PO page:

 

NewForm(frmPOInfo);Set(_submitNewPOSUccess,false);ClearCollect(POCollection, {ItemID: 0,POItem: "", ItemQty: 0, ItemCost: 0, ItemTotal: 0});Clear(POCollection);Navigate(scrNewPO, ScreenTransition.Cover)

 

Once on the PO Page, the form is pre-filled and will be written to a sharepoint list with the "master" data. The user simply enters the items they require and hit the "save" icon to add a new row. When done, they hit the SAVE button that triggers a SubmitForm() for the "master" data write to the Sharepoint List and then triggers a ForAll() and Patch() via the OnSuccess() of the form (as I need the ID of the "master" data to be written back to the "details" list). This works like a charm. Code below:

 

ForAll(POCollection, If(!IsBlank(txtItem), Patch(PO_Details, Defaults(PO_Details), {Title:Now() & " " & ItemID, ItemName:txtItem.Text, ItemQty:Value(txtQty.Text), ItemCost:Value(txtItemCost.Text), ItemTotal:Value(txtItemTotal.Text), MasterID: frmPOInfo.LastSubmit.ID})));Set(_submitNewPOSuccess, true);Navigate(scrSuccess)

 

The problem that I face is that the patch ever only writes the details of the first item in the Collection and repeats it for n-number of entries in said collection. Now, before you say "AH-HA! Remove .Text and Value statements and you'll be golden!", I tried that as I read it on another post...the issue then is an iConvertible error that is triggered and no data is written...I have no idea what the iConvertible is referring to...as you all know...it doesn't come with any helpful insight!

 

I even tried generating a unique identifier and enabling force unique values. It works in the sense that the unique identifier is different in each list entry from the Patch() but the rest of the data is always what the first entry has. It never writes what items 2+ contain. Only ever what Item 1 has.

 

I'm at a loss....I'm sure it's a simple thing that I'm overlooking...but really would appreciate some help here.

 

Looking forward to hearing from someone!

 

Cheers!

1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Thorpe
Super User
Super User

It is getting late, so I might not be reading this correctly but from what I see the Patch() isn't using the column names from the collection except for the Title. The names txtItem, txtQty, txtItemCost and txtItemTotal appear to becoming from some text controls on one of the screens, so that would make sense if each item created from the iteration had the same values.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

3 REPLIES 3
Jeff_Thorpe
Super User
Super User

It is getting late, so I might not be reading this correctly but from what I see the Patch() isn't using the column names from the collection except for the Title. The names txtItem, txtQty, txtItemCost and txtItemTotal appear to becoming from some text controls on one of the screens, so that would make sense if each item created from the iteration had the same values.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

Hi Jeff,

 

Makes total sense ... I'm calling a repeating text control rather than the collection column....guess I was going code blind lol.

 

I'll make the changes in the AM and let you know, but I feel like that'll do it.

 

Thanks for pointing that out!!

So yup...that was it.

 

I knew it was going to be something simple but I was blinded by looking at the same thing over and over again.

 

Thanks Jeff!

 

Cheers.

 

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

Top Solution Authors
Top Kudoed Authors
Users online (46,962)