Monday, 8 October 2018

Override packing slip id while creating packing slip through COC in D365

In this blog we will discuss how we can override packing slip id by creating & posting packing slip through chain of command method.

Recently I have came across this situation in which I want to override packing slip id as per some conditions if it returns true while creating and posting the packing slip.

After some code debugging I have found that SalesPackingSlipJournalCreate class is responsible for creating and posting of Sales order packing slips. In this class we have a method initJournalHeader which is responsible to initialize packing slip header values in which packing slip id also initializes OOTB. 

So when I wants to copy post event handler of initJournalHeader method, it through me error because this method access modifier declare as Protected, so according to that it is not a hook-able method and we cannot create an event for the particular method.













Note:
I have written a blog to handle above error Technique to use Pre-Event Handler functionality for Protected Method in AX7 / D365 please refer.


In order to achieve my requirement I have used chain of command method as shown in below images.

Packing slip navigation:










Method which will do the magic:

Method Explanation:
1- I have created a class SalesPackingSlipJournalCreate_Extension.
2- Set attribute ExtensionOf and provide a class SalesPackingSlipJournalCreate.
3- Declare method to override the packing slip id.
4- Use next keyword create a Chain of Command for the method. CoC is a design pattern where a request is handled by a series of receivers. 
5- In this you have noticed I have declare CustPackingSlipJour buffer, the reason is in D365 it is a bug it cannot get the variable buffer directly from parent class, so for that I have to declare the buffer to get the value.
6- In the end I have simply assign my custom value of PackingSlipId.


















Result:











That is all, If you have any questions or queries do comment in the comment section below.

No comments:

Post a Comment

How to Get Customer Free Text Invoice "Totals" form field value with X++ in D365FO

Customer free text invoices are an essential aspect of financial management in D365FO. In this blog, I have compiled all the code needed to ...