Saturday, June 23, 2018

Retrieve last approver name for any workflow

Below code can be used to retrieve last approver name for any workflow activated in Dynamics AX/ 365 Finance and operations.

 static void dtGetLastApproverName(Args _args)  
 {  
    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 == _salesRecId //PurchRecID  
    && workflowTrackingStatus.ContextTableId == tableNum(SalesTable) //SalesTable  
    && workflowTrackingTable.TrackingType == WorkflowTrackingType::Approval;  

    if (workflowTrackingTable.RecId > 0)  
    {  
      info(strFmt(“%1 – %2 “,userInfo.name, workflowTrackingCommentTable.RecId));  
    }  
 }  

No comments:

Post a Comment

Reindexing Dynamis AX database

Below script will create job to re-index and update statistics of dynamics ax database. In script below fill factor is used as 30%, revie...