Wednesday, 10 October 2018

Number sequence for purchase external packing slip number in ax 2012 X++

Problem.
It is a common case that users don’t want to manually enter external packing slip number while posting purchase packing slip. 
In Microsoft Dynamics, we can set number sequence only for internal packing slips, 
But there is no possibility to use the same numbers for external documents or assign another number sequence for them. 
The objective was to hide „Packing receipt” field and use the same number sequence as for internal purchase packing slips.

Tool.
I used the same objects, which are responsible for taking user’s input in „Product receipt” field and making it packing slip identifier.

Step by step.
What we have to do is:

1. Hide „Product receipt” field from PurchEditLines form so the user will not be able to enter any value.
2. Disable „FormLetterId” value validation for packing slips while posting a document as it is assigned later.
3. Use internal packing slip ID for external packing slip ID.

So…

1. PurchEditLinesForm_PackingSlip.num() method is indicating whether „Product receipt” field is visible or not. 
We have to modify it to return false.

\Classes\PurchEditLinesForm_PackingSlip

public boolean num()
{
return false;
// orig return true;
}
view rawNumber sequence for purchase external packing slip number [Dynamics AX2012; X++] hosted with by GitHub
2. After confirming that we want to post packing slip, system validates if packing slip ID is defined. 
We are setting it later, so let’s disable this validation, which happens in PurchSummary.checkFormLetterId() method.

\Classes\PurchSummary

public boolean checkFormLetterId(str _errorText)
{
...
this.setFormLetterIdFromTrans(VendDocumentSubTableMap::header(parmSubTable).Num);

// START Number sequence for purchase external packing slip number [Dynamics AX2012; X++]
if (documentStatus != DocumentStatus::PackingSlip)
// END Number sequence for purchase external packing slip number [Dynamics AX2012; X++]
if (!strLTrim(this.formLetterId()))
{
Ok = checkFailed(strFmt(_errorText, purchTable.PurchId));
}
// START Number sequence for purchase external packing slip number [Dynamics AX2012; X++]
}
// END Number sequence for purchase external packing slip number [Dynamics AX2012; X++]
...
}
View rawNumber sequence for purchase external packing slip number [Dynamics AX2012; X++] hosted with by GitHub
3. No we can use our internal packing slip number sequence values for external document. 
Packing slip header is initialized before we get the ID from sequence number, so we have to pick it earlier, and assign it to our external packing slip ID. The code in PurchPackingSlipJournalCreate class will look like this:

\Classes\PurchPackingSlipJournalCreate

public void initHeader()
{
...
// START Number sequence for purchase external packing slip number [Dynamics AX2012; X++]
if (!internalNumber)
{
[journalNumber, internalNumber, voucher] = this.getNumAndVoucher();
}

purchParmTable.Num = internalNumber;
vendPackingSlipJour.PackingSlipId = purchParmTable.Num;
// END Number sequence for purchase external packing slip number [Dynamics AX2012; X++]
...
}

protected void createJournalVersion()
{
FormLetterContract purchFormLetterContract = this.parmInterCompanyFormletterContract();
    
// START Number sequence for purchase external packing slip number [Dynamics AX2012; X++]
// orig [journalNumber, internalNumber, voucher] = this.getNumAndVoucher();
// END Number sequence for purchase external packing slip number [Dynamics AX2012; X++]

...
}
view rawNumber sequence for purchase external packing slip number [Dynamics AX2012; X++] hosted with by GitHub
That’s all. „Product receipt” isn’t visible now and it is automatically taken from the internal number sequence.

No comments:

Post a Comment

DefaultDimension in d365 FO X++

 Navigate to PurchTable methods you can find with DefaultDimension this.DefaultDimension = this.mergeDimension(this.getDefaultDimension(),th...