To find first approver and last approver for the workflow

To find first approver and last approver for the workflow:
static void Job54(Args _args)
{
    WorkflowTrackingStatusTable     workflowTrackingStatusTable;
    WorkflowTrackingTable           workflowTrackingTable;
    DirPersonUser                   dirPersonUser;
    UserInfo                        userInfo;

//First Approver-Start

    select workflowTrackingStatusTable
        join workflowTrackingTable
        where workflowTrackingStatusTable.ContextRecId == 5637144644
        && workflowTrackingTable.TrackingContext == workflowtrackingcontext::WorkItem
        && workflowTrackingTable.TrackingType == workflowtrackingtype::Approval
        && workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId
        join userInfo
            where userInfo.id == workflowtrackingtable.User
            join dirPersonUser
            where dirPersonUser.User == userInfo.id;

    info(strFmt("First Approver-%1",userInfo.name));
 
//First Approver-End


//LastApprover-Start

    select workflowTrackingStatusTable
        join workflowTrackingTable order by CreatedDateTime desc
        where workflowTrackingStatusTable.ContextRecId == 5637144644
        && workflowTrackingTable.TrackingContext == workflowtrackingcontext::WorkItem
        && workflowTrackingTable.TrackingType == workflowtrackingtype::Approval
        && workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId
        join userInfo
            where userInfo.id == workflowtrackingtable.User
            join dirPersonUser
            where dirPersonUser.User == userInfo.id;

    info(strFmt("last Approver-%1",userInfo.name));

//LastApprover-Start
}

Comments

Popular posts from this blog

Getting Workflow Approvers In Dynamics AX (AX 2012)

Creating a numbersequence in form level in ax 2012

AX 2012 R3 Line by line invoicing the sales order using X++ code