viernes, 11 de noviembre de 2011

Operation HelpText

Just received a real swine of an email from the boss.  We have in our Extended Data Type (EDT) lots of entities that have the Label type property but with no HelpText.  What this means is that in some forms as the user tabs from field to field those without a HelpText value will continue showing the previous EDT's value in the form's status bar at the bottom.  It's a bug in my opinion and the status bar should surely be empty.

I started manually working at this, merely copying the Label to the HelpText property value.  We should really be careful here as some EDTs are used interchangeably, between Vendors and Customers for example, so you have been warned.
As you can see, I started manually stepping through our work updating stuff as we go...  Tedious. 
I know, why don't we iterate over the AOT and find these babies using X++!

static void listEDTWithoutHelpText(Args _args)
{
    #TreeNodeSysNodeType
    TreeNode              edtNode   = TreeNode::findNode("Data Dictionary\\Extended Data Types");
    TreeNodeIterator      ir        = edtNode.AOTiterator();
    TreeNode              childNode;
    str                   label;
    ;
    if (ir)
    {
        childNode = ir.next();
        while (childnode)
        {
            // Check for:
            //   Has a label, Not extended from another entity, (Below VAR/USR), No HelpText.
            label = childNode.AOTgetProperty("label");
            if (label
                && !childNode.AOTgetProperty("extends")
                && (!strStartsWith(label, "@SYS")         // Modify this stuff yourself!
                    && !strStartsWith(label, "@SYP")      // Modify
                    && !strStartsWith(label, "@ESP"))     // Modify
                && !childNode.AOTgetProperty("HelpText"))
            {
               info(strfmt("EDT :%1, %2", childNode.AOTname(), childNode.AOTgetProperty("label")));
            }

            childNode = ir.next();
        }
    }
}


We're nearly there.  We need to de the same with Base Enum types, and also there is an omission above in so much that if we use some @SYS labels in our own entities, such as 'Name', then they won't be caught.
Now we need to pass the list to the junior developer to fix :)

EDIT*I* needed to fix it :(

Below is code listing the Base Enum types, but adding them to a project as well! Update the 'Project2' value before running.

static void listBaseEnumsWithoutHelp(Args _args)
{
    #define.projNameToAddEDTs ('Project2')
    #TreeNodeSysNodeType
    TreeNode              edtNode   = TreeNode::findNode("Data Dictionary\\Base Enums");
    TreeNodeIterator      ir        = edtNode.AOTiterator();
    TreeNode              childNode;
    str                   label;
    ProjectNode              projNode;

    void findProjNode(str _projName)
    {
        ProjectListNode       listp  = infolog.projectRootNode().AOTfindChild("Shared");
        TreeNodeIterator      irp    = listp.AOTiterator();
        ;
        if (irp)
        {
            projNode = irp.next();
            while (projNode)
            {
                if (projNode.AOTgetNodeType() == #NT_PROJECT_NODE
                    && projNode.AOTname() == _projName)
                {
                   return;
                }
                projNode = irp.next();
            }
        }
        // Not found
        projNode = null;
    }
    ;
    if (ir)
    {
        findProjNode(#projNameToAddEDTs);

        childNode = ir.next();
        while (childnode)
        {
            label = childNode.AOTgetProperty("label");
            if (label
                //&& !childNode.AOTgetProperty("extends")
                && (!strStartsWith(label, "@SYS")         
                    && !strStartsWith(label, "@SYP")      
                    && !strStartsWith(label, "@ESP"))     
                && !childNode.AOTgetProperty("Help")) //HelpText
            {
                info(strfmt("ENUM :%1, %2", childNode.AOTname(), childNode.AOTgetProperty("label")));
                if (projNode)
                {
                    projNode.addNode(childNode);
                }
            }

            childNode = ir.next();
        }
    }
}

All in all a far less painful update process now.

No hay comentarios:

Publicar un comentario