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