Saturday, July 25, 2020

How to use the method parameter in Pre or Post Event Handler of an existing method of a table/class using X++ in D365 FO



Most of the times we have seen such scenarios where the requirement is to call or assign a different value to an existing method parameter for a table or a class in pre or post event handlers.

In case of such predicaments there is an approach which comes handy and that is to simply use the getArg( ) method of the args class variable.


Let's take a look at the following example.

There is a table PurchLine which contains populate( ) method.

class PurchLine
{
     public static void populate(ItemId _invid)
    {
         // Method definition goes here.
     }
}


Now we need to assign a value to the invid parameter in Pre or Post event handler for this method.


This is how we can achieve our objective :-


public static void populate_Post(XppPrePostArgs _args)
{
    PurchLine purchLine = _args.getArg(identifierStr(_purchLine)) as PurchLine;

    str  a         = _args.getArg(identifierStr(_invid));

    a = "1167"; // We have assigned a new value
 }

In the above example getArg( ) method has helped us to achieve our goal very easily.


There might be hundreds of other approaches as well but this one might come handy for most of us when we need to work with method parameters in Pre or Post Event Handlers.



How to reverse Free Text Invoice Voucher entries without Dialog

 Hey Folks ,  This blog post is in continuation of the previous post for Reversing Free Text Invoice Voucher entries with Dialog. Only diffe...