Get workflow approval data and approval user x++ code (Dynamics 365 Finance and Operations)

 

In this lesson, we will fetch the workflow approval date and user name using dynamics 365 code (x++ language). Sometimes, you may get a requirement that you have a form and on that form, you have a workflow-enabled and you have to pick the workflow approval user name or approval date and show them in the SSRS report or inquiry. So, how will you do that? Ok, Let's see the code.

For this purpose, generally, two tables are involved (Workflowtrackingtable and Workflowtrackingstatustable) and these are root tables even if you have to take any other value like context or you can commence from here.


    /// <summary
    /// Get workflow approval date time
    /// </summary>
    /// <param name = "_Id">AADemoId</param>
    /// <returns>utcdatetime</returns>
   
    public static utcdatetime getWorkflowApprovalDateTime(AADemoId _Id)
    {
        Workflowtrackingtable   workflowtrackingtable;
        Workflowtrackingstatustable workflowtrackingstatustable;


        select firstonly  workflowtrackingstatustable
            join workflowtrackingtable
            where  workflowtrackingstatustable.RECID ==           workflowtrackingtable.WORKFLOWTRACKINGSTATUSTABLE
            && workflowtrackingtable.TrackingContext == workflowtrackingcontext::WorkItem 
            && workflowtrackingtable.TrackingType ==   workflowtrackingtype::Approval 
            && workflowtrackingstatustable.Document like '*'+_Id+'*';
           
            return workflowtrackingtable.CreatedDateTime;
    }

Happy Learning

Comments