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

SalesStatus automatically set to "Cancelled" on SalesLine

(0) ShareShare
ReportReport
Posted on by 13,107 Most Valuable Professional

I am creating sales order Via x++.

The header and the line(s) are created successfully, But the sales line status is auto set Cancelled (Once there is a quantity on the sales line).

salesLine.clear();
salesLine.initValue();
salesLine.SalesId = salesTable.SalesId;

salesLine.initFromSalesTable(salesTable);
salesLine.CustomerLineNum = 1;
salesLine.LineNum = 1;
salesLine.modifiedFieldValue(fieldstr(salesLine,LineNum));
salesLine.SalesUnit = pmgParameters.SalesUnit;
salesLine.SalesCategory = pmgparameters.CapacitySalesCategory;
salesLine.initFromItemOrCategory("",salesLine.SalesCategory,EcoResCategory::find(pmgparameters.CapacitySalesCategory).Name);
salesLine.modifiedFieldValue(fieldstr(salesLine,SalesCategory));
salesLine.PmgCapacity = pMGMSRTable.DigitalTotal;
salesLine.PmgConstraintCapacity = pmgMonthlyGeneratorTransLine.TotalConstraint;
salesLine.PmgLessShiroro = - pMGMSRTable.SGRTotal / pmgParameters.ShiroroFactor;
salesLine.PmgNetCapacity = salesLine.PmgCapacity + salesLine.PmgConstraintCapacity + salesLine.PmgLessShiroro;
salesLine.SalesQty = salesLine.PmgNetCapacity;
salesLine.PmgCapacityTariff = pmgTariffCodes.ApplicableCapitalRecoveryRate + pmgTariffCodes.ApplicableFixedOMRate;
salesLine.SalesPrice = salesLine.PmgCapacityTariff;
salesLine.LineAmount = salesLine.SalesQty * salesLine.SalesPrice;
salesLine.SalesStatus = SalesStatus::Backorder;
salesLine.Name = strFmt("Capacity for the month of %1",PMGMonthlyDigitalReadingTable.PMGMonth);
salesLine.insert();

if(!salesLine.validateWrite())
{
throw exception::Error;
}

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Komi,

    Could you please share the code for creating the sales order header?

  • Komi Siabi Profile Picture
    13,107 Most Valuable Professional on at

    Hi Gujan,

    Please see below :

    ttsbegin;

           numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());

           numberSeq.used();

           salesTable.SalesId = numberSeq.num();

           salesTable.CustAccount = custAccount;

           salesTable.initFromCustTable();

           salesTable.SalesType = SalesType::Sales;

           salesTable.InvoiceAccount = custAccount;

           salesTable.SalesStatus = SalesStatus::Backorder;

           salesTable.ReceiptDateRequested = today();

           salesTable.ShippingDateRequested = today();

           salesTable.insert();

           ttscommit;

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

    Hi Komi,

    I don't see any issue in the code as such. It does look like you have a few customized fields. Do you have any customization on the insert method? Have you tried to debug the code to check if where the SalesStatus field value is getting set to "Cancelled".

    Additionally, you don't need this piece of code for throwing an error.

    if(!salesLine.validateWrite())
    {
    throw exception::Error;
    }

    Before insert, the validateWrite method would already have been called. You can put your code in a try - catch block instead.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Please debug it to learn when the sales line status changes.

    Once you find it out, perhaps you can already find a solution. If not, just let us know what caused it and we can figure it out together.

    Thanks!

  • Verified answer
    André Arnaud de Calavon Profile Picture
    301,020 Super User 2025 Season 2 on at

    Hi Komi,

    There are multiple quantity fields on the salesline table. E.g. fields for the inventory unit and remainder fields. If there is a sales quantity and no remainder, the line status will be set automatically. To solve your issue, you have to call the static method SalesLine::salesQtyModified()

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 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans