Create purchase requisition using x++

A purchase requisition is an internal document that authorizes the Purchasing department to buy items or services. If you want to create purchase requisition using x++ in D365FO and AX 2012, you are at the right place.
In my this article, I will show you how to create Purchase requisition using programming language i.e. X++. See the steps below:
- Create a runnable job in D365FO named as CreatePurchaseRequisition
- Copy and paste the below code in your job
class CreatePurchaseRequisition
{
public static void main(Args _args)
{
PurchReqTable purchReqTable;
PurchReqLine purchReqLine;
ttsbegin;
//Purchase requisition header
purchReqTable.clear();
purchReqTable.initValue();
purchReqTable.PurchReqId = NumberSeq::newGetNum(PurchReqTable::numRefPurchReqId()).num();
purchReqTable.PurchReqName = 'PR from X++ Job';
purchReqTable.insert();
//Purchase requisition lines
purchReqLine.clear();
purchReqLine.initValue();
purchReqLine.initFromPurchReqTable(purchReqTable);
purchReqLine.ItemId = "PRD000711"; //Replace ItemId according to your system's data
purchReqLine.BuyingLegalEntity = CompanyInfo::find().RecId;
purchReqLine.InventDimIdDataArea = curext();
purchReqLine.PurchQty = 2;
purchReqLine.modifiedField(fieldNum(purchReqLine,ItemId));
purchReqLine.insert();
ttscommit;
info(strFmt("Purchase requisition '%1' created successfully",purchReqTable.PurchReqId));
}
}
- Modify the code according to your system’s data. You can see comments in the code.
- Execute the job
- Job will generate the Purchase requisition
- A message will be displayed with Purchase requisition number
- Go to Procurement & Sourcing -> All Purchase requisitions -> All purchase requisition
- Find out your newly created Purchase requisition
Above code is just an example to show you how can purchase requisition be created. You can use this code according to your requirements. So, in this way you can use create purchase requisition using X++ D365FO.
Moreover, if this helps you, please Like, Comment and Share to help other people. If you found any ambiguity or a better solution, please feel free to ask.
Website: Click here
Blog: Click here
YouTube: Click here
GitHub: Click here
Most people fail in life not because they aim too high and miss, but because they aim too low and hit. – Les Brown
Pingback:Create purchase requisition using x++ - Microsoft Dynamics AX Community