Monday, 9 February 2015

difference between main and run method in ax 2012 class

Main is the entry point of a class, you can use it as a constructor method of your class, depending on the argument you can instantiate a new child class and return it's object. 


Run is used to write the code to process the business logic for that class
In addition to that, Main is recognized by kernel and is executed when you call that class from the Menu item. On the other hand, Run is just a user defined method that by design should be used to execute the main job of the class.

  1. Create a X++ job in the Jobs AOT node. Place code that invokes your class in the job body and press F5 to run.
  2. Create a main method on your class with the following signature:

static void main (Args _args) 
    // Your X++ code here. 
}

main method of a class in AX 2012

public static void main(Args args)
{
    DirNameSequenceUpdate nameSequenceUpdate;
    DirNameSequence nameSequence;

    // Find name sequence
    if(args.record() && args.record().TableId == tablenum(DirNameSequence))
    {
        nameSequence = args.record();

        // Run batch
        nameSequenceUpdate = new DirNameSequenceUpdate();
        nameSequenceUpdate.parmnameSequenceRecId(nameSequence.RecId);
        if (nameSequenceUpdate.prompt())
        {
            nameSequenceUpdate.run();
        }
    }
}

No comments:

Post a Comment

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...