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

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?

  • 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.

  • 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

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,421 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".

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,748 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans