Saturday, 9 April 2016

AX 7 Form Event Handlers


We must use Event handlers, if you are using Extension Model Development in AX 7.

1. How we can handle the Datasource fields based on active/selected record, in Event handler method.

[FormDataSourceEventHandler(formDataSourceStr(FormName, DataSource), FormDataSourceEventType::Activated)]
public static void DataSource_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{
    Common    common = sender.cursor();
    sender.object(fieldNum(DataSource, ProjActivityNumber)).enable(common.ProjId);
}

2. How we can handle the Controls like, Tab/TabPage/Button etc
 
[PostHandlerFor(formStr(
LedgerJournalTable), formMethodStr(LedgerJournalTable, init))]
    public static void LedgerJournalTable_Post_init(XppPrePostArgs args)
    {
        FormRun             sender = args.getThis();
        LedgerJournalType   journalType = sender.args().parmEnum();

        if (journalType == LedgerJournalType::Assets)
        {
            sender.control(sender.controlId(formControlStr(LedgerJournalTable, YourControl))).visible (true);
        }
 
3. To get new number sequence reference for an existing module.
 
 
    [PostHandlerFor(formStr(AssetParameters), formMethodStr(AssetParameters, numberSeqPreInit))]
    public static void AssetParameters_Post_numberSeqPreInit(XppPrePostArgs args)
    {
        TmpIdRef                                tmpIdRef;
        NumberSeqScope                          scope;
        NumberSeqApplicationModule              numberSeqApplicationModule;
        container                               numberSequenceModules;
 
        numberSequenceModules = [NumberSeqModule::Asset];
        numberSeqApplicationModule = new NumberSeqModuleAsset_XXX();
        scope = NumberSeqScopeFactory::createDataAreaScope();
        NumberSeqApplicationModule::createReferencesMulti(numberSequenceModules, scope);
        tmpIdRef.setTmpData(NumberSequenceReference::configurationKeyTableMulti(numberSequenceModules));
 
        args.setArg('tmpIdRef',tmpIdRef);
    }
 
 
 

 
 

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  2. Thank you, it worked for me.

    ReplyDelete