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);
    }
 
 
 

 
 

Label editor in AX 7

We have Lookup Label/Text option in earlier versions of AX in X++ Code Editor.
We don’t have exact option in AX 7. Use label search short cut (Ctrl-R, Ctrl-L).