web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Negative sales line quantity with X++

(0) ShareShare
ReportReport
Posted on by 55

Hi.

I want to create a sales order via X code which lines have negative values on the SalesQty field.

I already have a class that creates the sales orders correctly with positive quantities, the problem comes when I try to create a line with a negative quantity, when I try to do It, I get the following messages:

"Quantity may not change sign." "Update has been canceled."

I am able to change the quantities of the already created SO lines to negative values correctly from the sales orders menu in the graphic interface, so how would I do It by code?

This is the code I tried:

SalesQty negSalesQty;

negSalesQty = -salesLine.SalesQty;
salesLine.LineAmount = salesLine.calcLineAmount();
salesLine.update();

I have the same question (0)
  • Alex VN Profile Picture
    1,994 on at

    Hi,

    I can see in the code that you are trying to update a Sales Line with LineAmount = salesLine.calcLineAmount() but nothing related to the Sales Qty and also it is update instead of create a new line. May I know what you are trying to achieve?

  • chrisrojas Profile Picture
    55 on at

    Hi Alex,

    I´m sorry, I forgot to write the line of code where I assign the negSalesQty value to the sales qty field in the question, but it is in the code and I'm getting the same messages when I try to update.

    SalesQty negSalesQty;
    negSalesQty = -lines.SalesQty;
    salesLine.SalesQty = negSalesQty;
    salesLine.LineAmount = salesLine.calcLineAmount();
    salesLine.update();

    I'm trying to create a credit sales order, so I need to create a new sales order that has the same values of an original SO but with the sales line quantities changed to negative values.

    If it helps, the "Quantity may not change sign" message I'm getting is a warning message.

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Chris,

    From your code, I believe you are creating sales order lines and then updating them with the negative quantity from another sales order line record. Instead of doing an update, can you try to set the negative quantity before creating the new line?

    salesLine.SalesQty = negSalesQty;
    ...
    ...
    salesLine.createLine(true, true, true, true, true, true);

    Is there any any reason you are inserting the line first and then doing an update?

  • chrisrojas Profile Picture
    55 on at

    Hi Gunjan,

    I was inserting the line first and doing the update because It was written like that in the example I was using, but I tried setting the negative value before inserting the line as you said and It worked fine, thank you!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 565 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans