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, ...
Suggested Answer

PO CRETION ISSUE(Purch order status)

(0) ShareShare
ReportReport
Posted on by 124

Hi everyone,

Can anyone please help me in below code. I am using below code to create a PO. So my PO is getting created, but by default its PurchOrderStatus is Cancelled due to which i am not able to Receive PO.

AxPurchTable                axPurchTable;

PurchTable                    purchTab;

PurchLine                      purchLn;

numseq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
numseq.used();
purchtab.clear();
purchTab.initValue();
purchTab.PurchId = numSeq.num();
PurchTab.initFromVendTable(VendTable::find('XX1200'));
axPurchTable = axPurchTable::newPurchTable(purchTab);
axPurchTable.parmPurchaseType(PurchaseType::Purch);
axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
axPurchTable.parmAccountingDate(systemDateGet());
axPurchTable.parmPurchStatus(PurchStatus::None);
axPurchTable.parmInventSiteId(salesTab.InventSiteId);
axPurchTable.parmInventLocationId(salesTab.InventLocationId);
purchTab.insert();

PurchLn.clear();
PurchLn.initValue();
PurchLn.PurchId = purchTab.PurchId;
PurchLn.ItemId = cusPckngSlpTrns.ItemId;
PurchLn.LineNumber = lastlinecount + 1;
PurchLn.PurchQty = cusPckngSlpTrns.Qty;
PurchLn.PurchUnit = 'LTR'
PurchLn.VendAccount = 'V-001';
PurchLn.VendGroup = VendTable::find('V-001').VendGroup;
PurchLn.PurchPrice = invntItmPrc.Price;
PurchLn.InventDimId = invDimLoc.inventDimId;
PurchLn.CurrencyCode = 'INR';
PurchLn.PurchStatus = 1;
PurchLn.insert();

I have the same question (0)
  • GirishS Profile Picture
    27,827 Moderator on at

    Hi D365_FO_Technical_Te

    Have you debugged the code and find out the value of PurchStatus while inserting records in PurchTable and exactly at which line the status changed to cancelled. Maybe you can navigate inside the insert method of purch table.

    Thanks,

    Girish S.

  • D365_FO_Technical_Te Profile Picture
    124 on at

    Thanks girish for your reply, i debug it but till insertion of my code, it is showing same value of purchstatus which i am writing in my code.

  • GirishS Profile Picture
    27,827 Moderator on at

    I guess there must be some logic inside insert method of PurchTable or some customization you have done.

    So go inside(F11) of the PurchTable insert method and debug line by line.

    Thanks,

    Girish S.

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Can you change the PurchStatus at header level to PurchStatus::BackOrder and check?

    Also at line level, what does purch status = 1 mean?

  • D365_FO_Technical_Te Profile Picture
    124 on at

    HI Bharani,

    I have already change the code to PurchStatus::BackOrder at header and line level both, but still same issue

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Try debugging the code by putting the break points at insert(), validatefield (), validatewrite() methods and in your job and check where it is getting changed.

  • Suggested answer
    D365_FO_Technical_Te Profile Picture
    124 on at

    Hello everyone, 

    This issue got resolved,

    So issue was, we have to use PurchLine.CreateLine method instead of PurchLine.insert Method.

    AxPurchTable                axPurchTable;

    PurchTable                    purchTab;

    PurchLine                      purchLn;

    numseq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
    numseq.used();
    purchtab.clear();
    purchTab.initValue();
    purchTab.PurchId = numSeq.num();
    PurchTab.initFromVendTable(VendTable::find('XX1200'));
    axPurchTable = axPurchTable::newPurchTable(purchTab);
    axPurchTable.parmPurchaseType(PurchaseType::Purch);
    axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
    axPurchTable.parmAccountingDate(systemDateGet());
    axPurchTable.parmPurchStatus(PurchStatus::Backorder);
    axPurchTable.parmInventSiteId(salesTab.InventSiteId);
    axPurchTable.parmInventLocationId(salesTab.InventLocationId);
    purchTab.insert();

    PurchLn.clear();
    PurchLn.initValue();
    PurchLn.PurchId = purchTab.PurchId;
    PurchLn.ItemId = cusPckngSlpTrns.ItemId;
    PurchLn.LineNumber = lastlinecount + 1;
    PurchLn.PurchQty = cusPckngSlpTrns.Qty;
    PurchLn.PurchUnit = 'LTR'
    PurchLn.VendAccount = 'V-001';
    PurchLn.VendGroup = VendTable::find('V-001').VendGroup;
    PurchLn.PurchPrice = invntItmPrc.Price;
    PurchLn.InventDimId = invDimLoc.inventDimId;
    PurchLn.CurrencyCode = 'INR';
    PurchLn.PurchStatus = PurchStatus::Backorder;;
    PurchLn.createLine();

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans