How to: Generate the Packing Slip for a SalesOrder of type RequiredItem.

Today we are going to show you how to do a Packing Slip for a Sales Order that has been generated from a project.

First how do we generate the order from a project? On a functional way we have to go to a project and then click on the button shown below:

captura1

By code, it’s a normal sales order but with type required item, for example:

 X++ |  copy code |? 
01
02
static void SalesOrderCreate(Args _args)
03
{
04
NumberSeq numberSeq;
05
SalesTable salesTable;
06
SalesLine salesLine;
07
ttsBegin;
08
numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
09
numberSeq.used();
10
salesTable.SalesId = numberSeq.num();
11
salesTable.initValue();
12
salesTable.CustAccount = '1101';
13
salesTable.SalesType = SalesType::ItemReq; // THIS IS THE IMPORTANT LINE
14
salesTable.initFromCustTable();
15
if (!salesTable.validateWrite())
16
{
17
throw Exception::Error;
18
}
19
salesTable.insert();
20
salesLine.SalesId = salesTable.SalesId;
21
salesLine.ItemId = '1205';
22
salesLine.createLine(true, true, true, true, true, true);
23
ttsCommit;
24
info(strFmt(
25
"Sales order '%1' has been created", salesTable.SalesId));
26
}
27

Now that we have the sales order, we need to generate the packing slip. We need to set the DocumentStatus enum value to ProjectPackingSlip, to do so we will use the following code:

 X++ |  copy code |? 
1
2
static void createSalesOrder(Args _args)
3
{
4
SalesFormLetter formLetterObj;
5
formLetterObj = SalesFormLetter::construct(DocumentStatus::ProjectPackingSlip); // THIS IS THE IMPORTANT LINE
6
formLetterObj.update(SalesTable::find("SO-101248"));
7
}
8

And that’s it now you will have your packing slip for the sales order you created. Hope this helps and see you next time.

  • Itsuki Minami

    by LP