Monday, March 31, 2014

Models: How to enumerate list of models from X++ [AX 2012]

I'm creating custom Best Practice checks and I needed to enumerate the existing models in my model store. Here is a simple job that demonstrates how.  My next post will build on this.  The code is a tweak of \Classes\SysModelStore\buildSelectionModels.

static void jobEnumerateModels(Args _args)
    SysModel sysModel;
    SysModelManifest sysModelManifest;
    container selectionList;

    // Select models from specified layer
    while select Model, Name, Publisher, DisplayName from sysModelManifest
        join firstonly Layer from sysModel
        where sysModel.RecId == sysModelManifest.Model &&
              sysModel.Layer == UtilEntryLevel::usr
        selectionList += [SysListSelect::packChoice(strFmt('DisplayName: "%1"\n ModelName: "%2"\n Publisher: "%3"', sysModelManifest.DisplayName, sysModelManifest.Name, sysModelManifest.Publisher), any2int(sysModelManifest.Model), false)];

No comments:

Post a Comment