Sunday, October 28, 2012

Get fields set in the workflow configuration conditions

Hi Folks,

I have been busy with my project for sometime and so couldn't post anything on my blog. I have got an interesting post for today.

 i.e., The below code snippet will help you to get the fields or parm methods which is set in the query condition of Workflow configuration in AX 2009. I hope this would work good in AX 2012 as well.

    WorkFlowElementTable    elementTable;
    WorkflowStepTable       workflowStepTable;
    ExpressionTable         expressionTable;
    XmlTextReader           xmlTextReader ;
    str                     attributeName, attributeValue;
    Map                     parmMethodMap;
    Map                     fieldsMap;
    int                     delimiterPosition;
    TableName               tableName;
    FieldName               fieldName;
    parmMethodMap = new Map(Types::String, Types::String); // Stores the names of parm methods used in the conditions of a workflow configuratoion
    fieldsMap     = new Map(Types::String, Types::String); // Stores the names of parm methods used in the conditions of a workflow configuratoion    while select ExpressionId, ExpressionDefinition from expressionTable join ElementId, ExecuteStepId from workflowStepTable
                                                                         join ConfigurationId from elementTable
                                                                        where elementTable.ConfigurationId == _configId// Pass an active configuration id
                                                                           && workflowStepTable.ElementId  == elementTable.ElementId
                                                                           && expressionTable.ExpressionId == workFlowStepTable.ExecuteStepId
        xmlTextReader = XmlTextReader::newXml(expressionTable.ExpressionDefinition, true) ;

            if (xmlTextReader.NodeType() == XmlNodeType::Element)
                while (xmlTextReader.MoveToNextAttribute()) // Read the attributes.                {
                    attributeName   = xmlTextReader.Name();
                    attributeValue  = xmlTextReader.Value();
                    if (attributeName == #Property)
                        delimiterPosition = strfind(attributeValue, #Delimiter, 1, strlen(attributeValue));
                        tableName = substr(attributeValue, 1, delimiterPosition-1);
                        fieldName = substr(attributeValue, delimiterPosition+1, strlen(attributeValue)-strlen(tableName)-1);
                        delimiterPosition = strfind(fieldName, #Delimiter, 1, strlen(fieldName));
                        if (delimiterPosition)
                            tableName = substr(fieldName, 1, delimiterPosition-1);
                            fieldName = substr(fieldName, delimiterPosition+1, strlen(fieldName)-strlen(tableName)-1);
                        if (substr(fieldname, 1, strlen(#ParmPrefix)) == #ParmPrefix)
                            parmMethodMap.insert(fieldName, tableName);
                            fieldsMap.insert(fieldName, tableName);

You can modify the above code as well to get the expressions and values used in the workflow configuration conditions as well.

Happy DAXing............... :)

No comments: