Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Commerce forum / Change unit of measure...
Commerce forum

Change unit of measure after SaveAttributeCartLineRequest on POS D365

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi All,

I got a problem when i try to change unit of measure (ChangeCartLineUnitOfMeasureOperationRequest) on PostProductSaleTrigger after I have call SaveAttributesOnCartLinesClientRequest to save my own attribute. You can see my picture below:

4011.pastedimage1566912594036v1.png

Here is my code:

6378.pastedimage1566913158062v2.png

8360.pastedimage1566913173751v3.png

But when i comment function addAttributeToCartLine i can change the unit of measure without error message pop-up on POS like this:

0636.pastedimage1566914005236v4.png

So, please help me. Thanks 

 

  • Oksana Kovaliova Profile Picture
    Oksana Kovaliova 3,597 on at
    RE: Change unit of measure after SaveAttributeCartLineRequest on POS D365

    Hi, you need also to check your async implementation - before sending Request for line #2, you should make sure request for line #1 has been finished. The same with line #3: make sure line #2 request is finished.

  • Oksana Kovaliova Profile Picture
    Oksana Kovaliova 3,597 on at
    RE: Change unit of measure after SaveAttributeCartLineRequest on POS D365

    You are welcome :) To understand async programming - google about Javascript/typescript and Promise handling - it is not really POS feature, it is general web development feature.

  • M Haseeb Profile Picture
    M Haseeb 70 on at
    RE: Change unit of measure after SaveAttributeCartLineRequest on POS D365

    Hi,

    I hope you are doing great.

    I'm facing same kind of issue when i'm going to update comment field of CartLine Object (SetCartLineCommentOperationRequest) in For Loop.

    In my case -> CartLine of Item display on screen user select one line then Add its Number and Number

    is saved on CartLine  comment Field successfully .

    On the other hand When select multi lines and add it Number and then through error.

    it update the value for one item and do not show error But when i update multiple time it through error which is similar to @phuocdinh

    Please Suggest me how can i find resolution of this issue .

    I'll be very thankful to you

    Regards,

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Change unit of measure after SaveAttributeCartLineRequest on POS D365

    Hi,

    Thanks for your reply, you can refer with Oksana Kovaliova's comment as below. She gave a correct simple example about how to use async execution.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Change unit of measure after SaveAttributeCartLineRequest on POS D365

    Oh, thank you a lot, i'm newbie with POS Coding, now i understood clearly how to use async execution with your pseudo code sample. If you have any document or cook book about POS Development, can you share with me?. Finally, thanks a lot for your reply. :)

  • Oksana Kovaliova Profile Picture
    Oksana Kovaliova 3,597 on at
    RE: Change unit of measure after SaveAttributeCartLineRequest on POS D365

    Hi,

    Are you sure 'change unit of measure' is always executed after 'add attribute' - and they are never running in parallel? It looks like 2 functions you are using return Promise, but 'change unit of measure' does not wait, while 'add attribute' is complete - this way cart versions can be messed and 'Cart version' error will be displayed.

    You can use RefreshCartClientRequest to refresh cart after adding an attribute, but this will not fix the issue 100%, if you do not execute all Promise functions in correct sequence.

    Correct async execution could look like (pseudo code sample)

    return this.addAttrubute()

    .then((result: bool) => {

      if (result){ //only change unit of measure, if add attribute finished successfully

       return this.changeUnitOfmeasure()

         .then((result: bool) => {

          //show error to user that UOM change failed

         }

      }

      else {

       //show error to user, that attribute was not added

      }

    })

  • M Haseeb Profile Picture
    M Haseeb 70 on at
    RE: Change unit of measure after SaveAttributeCartLineRequest on POS D365

    Hi phuocdinh,

    I hope you are doing great.

    I'm facing same kind of issue when i'm going to update comment field of CartLine Object in For Loop.

    In my case i have to update it on multiple time .

    it update the value for one item and do not show error But when i update multiple time it through error which is similar to you.

    please Suggest how you resolve the issue .

    I'll be very thankful to you

    Regards,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans