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

Community site session details

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

Why purchase requisition lines don't display in the form's grid when I create a purchase requisition through X++ code

(0) ShareShare
ReportReport
Posted on by 25

Greetings to everyone.

I created a Class object, that runs on Client, which executes an automated process to generate in bulk purchase requisitions in order to save time and effort for users having manually create them one by one.

This is the code i programmed in AX for the methods that generate both the header and lines for the PR.

protected PurchReqTable insertPurchReqHeader(
PurchReqBusinessJustificationCodes _reason,
container _readCon)
{
PurchReqBusJustification purchReqBusJust;
PurchReqTable purchReqTableLocal;
PurchReqName purchReqName = conPeek(_readCon, 3);

purchReqTableLocal.clear();
purchReqTableLocal.initValue();
purchReqTableLocal.PurchReqId = NumberSeq::newGetNum(PurchReqTable::numRefPurchReqId()).num();
purchReqTableLocal.BusinessJustification = _reason.RecId;
purchReqTableLocal.Originator = HcmWorker::userId2Worker(curUserId());
purchReqTableLocal.PurchReqName = purchReqName;
purchReqTableLocal.PurchReqType = PurchReqType::Purch;
purchReqTableLocal.RequiredDate = systemDateGet();
purchReqTableLocal.RequisitionPurpose = RequisitionPurpose::Consumption;
purchReqTableLocal.insert();

return purchReqTableLocal;
}

protected void insertPurchReqLine(container _readCon)
{
PurchReqLine purchReqLine;
VendTable vendTable;

PurchReqItemIdNonCatalog purchReqItemId = conPeek(_readCon, 3);
CompanyId companyId = conPeek(_readCon, 4);
EcoResCategoryName categoryName = conPeek(_readCon, 5);
PurchReqPrice purchReqPrice = conPeek(_readCon, 7);
TaxAmount taxAmount = conPeek(_readCon, 8);
LineAmount lineAmount;
PurchLineAmount purchLineAmount = conPeek(_readCon, 9);
CurrencyCode currency = conPeek(_readCon, 10);
VendAccount vendAccount = conPeek(_readCon, 11);

vendTable = VendTable::find(vendAccount);

purchReqLine.clear();
purchReqLine.initValue();
purchReqLine.initFromPurchReqTable(purchReqTable);
purchReqLine.initFromEcoResCategory(this.findCategoryByName(categoryName));
purchReqLine.initFromVendTable(vendTable);
purchReqLine.BuyingLegalEntity = CompanyInfo::findDataArea(companyId).RecId;
purchReqLine.LineType = PurchReqLineType::Category;
purchReqLine.ItemIdNonCatalog = purchReqItemId;
purchReqLine.PurchQty = 1;
purchReqLine.PurchUnitOfMeasure = UnitOfMeasure::findBySymbol('****').RecId;
purchReqLine.PurchPrice = purchReqPrice;
purchReqLine.LineAmount = taxAmount != 0 ? purchLineAmount + taxAmount : purchLineAmount;
purchReqLine.CurrencyCode = currency;
purchReqLine.DefaultDimension = this.getDefaultDimensionFromDisplayValues(_readCon);
purchReqLine.insert();
}

With the class deployed I then carried out developer tests at executing the process, and it successfully created the purchase requisitions, as shown in the following image.

PurchaseRequisition_5F00_AX_5F00_ListPage.jpg

However, if I click the edit button to open up the purchase requisition details form I found out that the data for the header is showing fine, but the lines are missing or not being displayed in the grid section.

PurchaseRequisition_5F00_AX_5F00_Detail.jpg

What's curious is that I checked the PurchReqLine table in the AOT and found out that the lines for each of the PR, created through the automated process, were generated without issues. In fact, the lines are displaying as well in the PR list page form, as shown in the first image above.

PurchReqLine_5F00_Table.jpg

Is this particular issue caused due to setup, permissions, or code lacking in my class?

And, how do I make the PR lines to display in the form?

I have the same question (0)
  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at
    RE: Why purchase requisition lines don't display in the form's grid when I create a purchase requisition through X++ code

    Hi GuidoMTY,

    Are you populating InventDimId field in PurchReqLine records? This is a required field for the lines being displayed on the form since InventDim is joined to PurchReqLine with a Link Type as "Inner join".

  • GuidoMTY Profile Picture
    25 on at
    RE: Why purchase requisition lines don't display in the form's grid when I create a purchase requisition through X++ code

    Thanks very much, Gunjan Bhattacharyya.

    In fact, now that you mention it the sources examples I researched most of them actually have a line that fills the InventDimId field in the purchase line.

    I mistakenly assumed I would not be needing the InventDimId field due that the PR generating from the process all make use of the Procurement Category and left in blank the ItemId field, since I do not need it.

    I'll rework my code to include filling in the InventDimId field, and then run tests again to confirm the results.

    Thanks again.

    P.S. I'm leaving the sources I found out on how to make PR through X++ code for anyone to consult.

    axaptalearning.blogspot.com/.../create-purchase-requisition-through-x.html

    sangeethwiki.blogspot.com/.../to-create-purchase-requisition-through-x.html

    basicax.blogspot.com/.../ax2012-r2-understanding-purchase.html

  • GuidoMTY Profile Picture
    25 on at
    RE: Why purchase requisition lines don't display in the form's grid when I create a purchase requisition through X++ code

    Included the lines to populate both the InventDimId and InventDimIdDataArea fields for the PurchReqLine table in my code, and then I ran another test with the process.

    The solution worked and now the lines are displaying in the PR details form grid.

    PurchaseRequisition_5F00_AX_5F00_Detail_5F00_solution.jpg

    Once again, thank you very much Gunjan Bhattacharyya.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,100

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 633 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans