cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AnthonyDB
Resolver I
Resolver I

Patch Collections & Custom Api | Update Etag with returned Api Etag

Hi guys,

 

I'm making a app for a production company. I have 2 issues with my patch method. 

 

  • varPatchRecord3 -> Outstanding Quantity is not updating in my Gallery wich is connected to my collection.
  • Last patch -> Returned Etag is not updating the current varThisItem.Etag

 

This is how the code works:

 

I have an icon in my gallery "productionList" wich has an "On select": Set(varThisItem,ThisItem)

 

This is my patch function:

 

Set(
    varPatchRecord,
    Patch(
        productionList,
        varThisItem,
        Defaults(productionList),
        {producedQuantity: varThisItem.producedQuantity + varAmount}
    )
);
Set(
    varPatchRecord3,
    Patch(productionList,
        varThisItem,
        Defaults(productionList),
        {outstandingQuantity: varThisItem.quantity - varPatchRecord.producedQuantity}
    )
);

Set(
    varPatchRecord2,
    MyFlow.Run(
        varThisItem.systemId,
        varThisItem.'@odata.etag',
        varPatchRecord.producedQuantity,
        varThisItem.productionFeedback,
        varPatchRecord3.outstandingQuantity
    )
);
    Patch(
        productionList,
        varThisItem,
        Defaults(productionList),
        {'@odata.etag': varPatchRecord2.'@odata.etag'}
    );

Set(
    varAmount,
    ""
);
Navigate(MainScreen)

 

  • The first patch is to patch the varThisItem.producedQuantity
  • The second patch i use varPatchRecord.producedQuantitiy for a calculation to patch the varThisItem.outstandingQuantity
  • The tirth patch i use my custom connector to run a flow wich will patch my custom Business Central table.
  • The last patch i want to update the varThisItem.Etag with the returned Etag from the Api Patch

 

Again the issues i have:

 

  • On return to the mainscreen: outstandingQuantity is not updated in the gallery nor the collection
  • When i wish to update this item again: Etag is not updated so i can't patch again.

I checked in Postman. The patch does work correctly the first time. producedQuantity and outstandinQuantity are correctly patched.

 

Also the returned Etag (varPatchRecord2.Etag) is correct i checked this. 

 

Can someone please help me with this?

1 ACCEPTED SOLUTION

Accepted Solutions

so another update, i found out that the patch function is a little bit buggy in Powerapps. Especially combined with local collections. So i changed my patch function to an updateIf function and now it works fine!

 

UpdateIf(
    productionList,
    varEtag=varThisItem.'@odata.etag',
    {'@odata.etag': varPatchBusinessCentral.'@odata.etag'}
);

View solution in original post

3 REPLIES 3
AnthonyDB
Resolver I
Resolver I

Update.

 

I changed my code to:

 

Set(
    varPatchRecord,
    Patch(
        productionList,
        varThisItem,
        Defaults(productionList),
        {
            producedQuantity: varThisItem.producedQuantity + varAmount,
            outstandingQuantity: varThisItem.quantity - (varThisItem.producedQuantity+varAmount)
        }
    )
);
Set(
    varPatchRecord2,
    myFlow.Run(
        varThisItem.systemId,
        varEtag,
        varPatchRecord.producedQuantity,
        varThisItem.productionFeedback,
        varPatchRecord.outstandingQuantity
    )
);
Patch(
    productionList,
    varThisItem,
    Defaults(productionList),
    {'@odata.etag': varPatchRecord2.'@odata.etag'}
);
Navigate(MainScreen)

 

Now my outstandingQuantity does update in the gallery. However my varThisItem.Etag does not update to the new Etag i receive.

 

Any Ideas?

so another update, i found out that the patch function is a little bit buggy in Powerapps. Especially combined with local collections. So i changed my patch function to an updateIf function and now it works fine!

 

UpdateIf(
    productionList,
    varEtag=varThisItem.'@odata.etag',
    {'@odata.etag': varPatchBusinessCentral.'@odata.etag'}
);

View solution in original post

FCGALLEG
Microsoft
Microsoft

Hi AntonyDB,

 

Thanks for share the info with the Community.

 

Javier

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 (6,221)