This is a sample Code to confirm and Post Project Item Requirement for Sales Order in Ax 2012 . You need to pass sales order in salesFormLetter class method update and you can pass transaction date or posting date as per your need it will create or post project sales order item requirement packing slip. Its same functionality as post button on project item requirement form.
SalesFormLetter salesFormLetter;
salesTable Salestablelocal;
str 200 msg;
salesid salesid;
if(salesid)
{
select Salestablelocal
where Salestablelocal.Salesid ==salesid
&& Salestablelocal.salestype==SalesType::ItemReq
&& Salestablelocal.SalesStatus==SalesStatus::Backorder;
if(Salestablelocal)
{
ttsBegin;
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
salesFormLetter.update(Salestablelocal);
salesFormLetter = SalesFormLetter::construct(DocumentStatus::ProjectPackingSlip);
salesFormLetter.update(Salestablelocal);
ttsCommit;
msg = "Item Requirement with Sales order id : " + salesid + " Posted ";
}
else
{
msg = "Item Requirement with Sales order id: "+ salesid + " already posted";
}
}
else
{
msg = "Item Requirement with provided Sales order id does not exists";
}