Pages

Monday, March 31, 2014

Creating custom keyboard shortcuts

I'm working on my own custom Editor Scripts and I wanted some keyboard shortcuts for the more frequently used scripts and I came across this fantastic blog post on how to do it in AX.

Keep checking back, as I'll make my own post if/when I can get a working demo up.

See it here: http://www.agermark.com/2011/04/create-your-own-shortcuts-in-ax-forms.html

Models: Notes about models and how to find what model your object is in via X++ [AX 2012]

I'm creating custom best practice checks, and I needed to determine what model an object was in from X++. This builds off of my previous post about enumerating models http://alexondax.blogspot.com/2014/03/models-how-to-enumerate-list-of-models.html.

Important notes/conclusions about models:

  • Models are layer-specific
    • Therefore a parent object (eg \Classes\SalesFormLetter\construct) may exist in the [Foundation] model in the SYS layer, but may also exist in the [USR Model] in the USR layer
  • You can have unlimited models in any layer
  • Models can contain objects that may be parents or children
    • This code below tells you what model C\SalesFormLetter is in, in the SYS layer.  If you have your own custom method in the CUS layer on this object, you will need to use SysDictMethod for example to identify it.
    • You would need to reflect on the objects entirely to fully identify an object.  This is proof of concept code
Models are very simple once you understand their concepts.  They can appear daunting at first.  You can use the TreeNode object to get the model.


static void jobGetObjectModel(Args _args)
{
    SysDictClass        sysDictClass = new SysDictClass(classNum(SalesFormLetter));
    SysModel            sysModel;
    SysModelManifest    sysModelManifest;
    
    
    select Model, Name, Publisher, DisplayName from sysModelManifest
        where sysModelManifest.Model == sysDictClass.treeNode().AOTGetModel()
        join firstonly Layer from sysModel
        where sysModel.RecId == sysModelManifest.Model &&
              sysModel.Layer == UtilEntryLevel::sys; // Change layer here
    
    if (sysModelManifest)
        info(strFmt("Model: %1", sysModelManifest.Name));
    else
        info("Object is not apart of model in given layer");

}

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)];
    }
    conView(selectionList);
}