Find Datatypes (updated)

Update of my old script to D365

class FindEDT
{
    public static void main(Args _args)
    {
        #AOT
        Dialog              dialog = new Dialog('Find EDT');
        str                 searchString;
        DialogField         dialogField = dialog.addField(extendedTypeStr(MCRSearchText), 'Search string');
        boolean             stopAfterFound;            
        ;
        if(dialog.run())
        {
            searchString = dialogField.value();
            if(!strScan(searchString, "*", 1, 999)) //no "*"
            {
                searchString = "*" + searchString + "*";
            }
            else if(strKeep(searchString,"*") == "*" && subStr(searchString,strLen(searchString),1)=="*") //just one final "*": beginns with
            {
                stopAfterFound = true;
            }
            info(strfmt("Find %1",searchString));
            if(searchString)
            {
                setPrefix('Extended Data Types');
                FindEDT::searchNodes(#ExtendedDataTypesPath, searchString, stopAfterFound);
                setPrefix('Base Enums');
                FindEDT::searchNodes(#BaseEnumsPath, searchString, stopAfterFound);
            }
        }
    }
    static void searchNodes(str _basePath, str _searchString, boolean _firstonly)
    {
        #AOT
        TreeNode            treeNode;
        TreeNodeIterator    treeNodeIterator;
        SysDictType         sysDictType;
        SysDictEnum         sysDictEnum;
        Boolean             found;
        ;
        treeNode = TreeNode::findNode(_basePath);
        treeNodeIterator = treenode.AOTiterator();
        treeNode = treeNode.AOTfirstChild();
        treeNode = treeNodeIterator.next();
        while(treeNode)
        {
            if(treeNode.treeNodeName() like "*" + _searchString + "*")
            {
                if(_basePath == #ExtendedDataTypesPath)
                {
                    sysDictType = sysDictType::newTreeNode(treeNode);
                }
                if(sysDictType)
                {
                    if (sysDictType.extend() && sysDictType.enumId())
                    {
                        info(strfmt("%1 (%2 - %3 -> %4)",treeNode.treeNodeName(), sysDictType.baseType()
                                    , extendedTypeId2name(sysDictType.extend()), enumId2Name(sysDictType.enumId()) ));
 
                    }
                    if(sysDictType.extend())
                    {
                        info(strfmt("%1 (%2 - %3)",treeNode.treeNodeName(), sysDictType.baseType()
                                    , extendedTypeId2name(sysDictType.extend()) ));
 
                    }
                    else if (sysDictType.enumId())
                    {
                        info(strfmt("%1 (%2 - %3)",treeNode.treeNodeName(), sysDictType.baseType()
                                    , enumId2Name(sysDictType.enumId()) ));
 
                    }
                    else
                    {
                        info(strfmt("%1 (%2)",treeNode.treeNodeName(), sysDictType.baseType()));
                    }
                }
                else
                {
                    info(strfmt("%1",treeNode.treeNodeName()));
                }
                found = true;
            }
            else if(_firstOnly && found)
            {
                return;
            }
            treeNode = treeNodeIterator.next();
        }
    }
}

Run with the following link:

https://usnconeboxax1aos.cloud.onebox.dynamics.com/?cmp=usmf&mi=SysClassRunner&cls=FindEDT

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *