Think Outside of the Box by Using X++ to Document Your Feature

By Bill Thompson | July 28, 2015

One of the extremely import tasks of development is to document what you have created.  This can include things such as comments within the code, but there are times you need more than that.   If you have created a rather complex piece of functionality (this could be anything from changing posting routine code to creating a custom module), you may be tasked with updating it at a later date (or you may inherit the code as well).  If this date is a couple of years AFTER the code has been deployed, will you remember what you were thinking when you designed the code?  Probably not.

Creating this type of documentation can be a bit of a tedious process, especially if you were not given a proper functional design document to create the feature.  Something to consider then is to create tools to help automate the process.

Dynamics AX has had the ability to work with Excel and Word for many versions, so why not utilize that functionality to create a document for your customization?  Utilize the built-in formatting commands to make the document have a standard format.  Here is some example code (it is not complete as it does not contain some macro definition code):

    Filename        fileName;
    str             myObject;
    UserInfo        userInfo;

    #AviFiles
    SysOperationProgress progress = new SysOperationProgress();

    // initialize globals
    modelName = _modelName;
    projName = _projName;
    enumsStarted = false;
    edtStarted = false;
    tablesStarted = false;

    progress.setCaption('Processing project …');
    progress.setAnimation(#AviUpdate);
    progress.update(true);


    fileName = 'c:\\' + _projName + '.doc';
    wordApplication = new COM(#wdProgId);
    wordApplication.visible(false);
    wordDocuments = wordApplication.Documents();
    wordDocument = wordDocuments.add();
    wordDocument.saveas(fileName);
    wordDocument.activate();

    wordStyles = wordDocument.styles();
    wordStyle = wordStyles.add('Titles');
    wordFont = wordStyle.font();
    wordFont.name('Calibri');
    wordFont.size(16);
    wordFont.bold(1);


    select firstOnly name from userInfo where userInfo.id == curUserId();

    this.insertDocHeader('\n',false,true);
    this.insertDocHeader('Project: ' + _projName + '\n',false,true);
    this.insertDocHeader('Model: ' + _modelName + '\n',false,true);
    this.insertDocHeader('Created by: ' + userInfo.name + ' (' + curUserId() + ')' + '\n',false,true);
    this.insertDocHeader('Date: ' + date2str(today(),213,2,DateSeparator::Slash,2,DateSeparator::Slash,4,DateFlags::FormatAll) + '\n',true,true);
    this.insertText('\n');
    this.insertText('

This document will contain (in the very least in the object listing section) a list of objects that exist in the above mentioned project and the above mentioned Model.  Certain types of objects will have additional information.');

OK, so that gives you a header, but what about the rest?  X++ has a construct called TreeNode().  You can use this to traverse your project, and update your document with any pertinent information you desire to pull from the metadata.   The dict* kernel classes can be a huge help in doing this as you can use those objects to pull property values, X++ code, etc. for your documentation.

A little snippet demonstrating part of this:

    // instantiate the dictClass object so we can process the class information
    dictClass = new SysDictClass(className2Id(_className));

    // dictTable instantiates successfully, so we can print out data
    if (dictClass)
    {
        if (!classesStarted)
        {
            classesStarted = true;
            this.insertBreak();
            this.insertHeading(int2str(sectionCounter) +'. Classes',1);
            this.insertText('\n',true);
            sectionCounter++;
        }

        this.insertHeading('Methods',3);
        this.insertText('\n',true);

        classMethods = dictClass.methods(true,true,false);

        sEnum = classMethods.getEnumerator();
        while (sEnum.moveNext())
        {
            dictMethod =    sEnum.current();
            methodName =    dictMethod.name();
            path        =   @'\Classes\' + dictClass.name() + @'\' + dictMethod.name();
            node        =   TreeNode::findNode(path);
            modelId     =   node.AOTgetProperty('Model');

            if (modelId == modelName)
            {
                this.insertHeading(MethodName,4);
                this.insertText('\n',true);
                this.insertCode(dictMethod.getSource());
                this.insertText('\n',true);
            }
        }

Once your tool does the ‘heavy lifting’, you can go in and add additional pertinent information, thoughts, etc. on the specific feature.

It is not a trivial effort to create the toolset to do this, but once created, it can be re-used as a real time saving device.

Related Posts


Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.

Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!