Tuesday, January 7, 2020

Get last approver of workflow in Dynamics AX

public Name workflowApprover(RecId _recId)
        {
            WorkflowTrackingStatusTable workflowTrackingStatus;
            WorkflowTrackingTable workflowTrackingTable;
            WorkflowTrackingCommentTable workflowTrackingCommentTable;
            UserInfo userInfo;
       
            select firstFast RecId, User from workflowTrackingTable
                order by RecId desc
            join workflowTrackingCommentTable
                where workflowTrackingCommentTable.WorkflowTrackingTable == workflowTrackingTable.RecId
            join UserInfo
                where UserInfo.id == WorkflowTrackingTable.User
            exists join workflowTrackingStatus
                where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId
            && workflowTrackingStatus.ContextRecId      == _recId
            && workflowTrackingStatus.ContextTableId    == tableNum(CICGBCreditCommittal)// your custom table on which workflow is enabled.
            && workflowTrackingTable.TrackingType == WorkflowTrackingType::Approval;
       
            if (workflowTrackingTable.RecId > 0)
            {
                return userInfo.name;
            }
            else
            {
                return '';
            }
       }


Display method.


display Name displayWorkflowApproverName()
{
    WorkflowTrackingStatusTable     workflowTrackingStatus;
    WorkflowTrackingTable           workflowTrackingTable;
    WorkflowTrackingCommentTable    workflowTrackingCommentTable;
    UserInfo                        userInfo;
    Name                            _name;


    select firstFast RecId, User from workflowTrackingTable
        order by RecId desc
            join workflowTrackingCommentTable
        where workflowTrackingCommentTable.WorkflowTrackingTable == workflowTrackingTable.RecId
            join UserInfo
        where UserInfo.id == WorkflowTrackingTable.User
            exists join workflowTrackingStatus
        where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId
    && workflowTrackingStatus.ContextRecId      == this.RecId
    && workflowTrackingStatus.ContextTableId    == tableNum(CICGBCreditCommittal)
    && workflowTrackingTable.TrackingType       == WorkflowTrackingType::Approval;

    if (workflowTrackingTable.RecId > 0)
    {
        _name=userInfo.name;
    }

    else
    {
        _name='';
    }
    return _name;

}

No comments:

Post a Comment