Monday, May 24, 2021

get last workflow approver in d365fo

  while select workflowTrackingTable  order by CreatedDateTime asc 

                                            where workflowTrackingTable.CreatedDateTime >= fromDateTimeValue

                                              &&  workflowTrackingTable.CreatedDateTime <= toDateTimeValue                             

        {

            actionTakenByName = DirPersonUser::userId2Name(workflowTrackingTable.User);//xUserInfo::find(true,workflowTrackingTable.User).name;


            select workflowTrackingStatusTable where workflowTrackingStatusTable.RecId == workflowTrackingTable.WorkflowTrackingStatusTable;


            select workflowCommentTable where workflowCommentTable.WorkflowTrackingTable == workflowTrackingTable.RecId;


            select workflowWorkItemTable where workflowWorkItemTable.CorrelationId == workflowTrackingStatusTable.CorrelationId;


            if(workflowTrackingStatusTable)

            {

                ttsbegin;

                afzWorkflowInquiryTable.DateTime            = workflowTrackingTable.CreatedDateTime;

                afzWorkflowInquiryTable.DocumentType        = workflowTrackingStatusTable.DocumentType;

                afzWorkflowInquiryTable.WorkflowInstance    = workflowTrackingStatusTable.InstanceNumber;

                afzWorkflowInquiryTable.WorkflowStatus      = workflowTrackingStatusTable.TrackingStatus;

                afzWorkflowInquiryTable.WorkflowStatusString = enum2Str(workflowTrackingStatusTable.TrackingStatus);

                afzWorkflowInquiryTable.SubmittedBy         = workflowTrackingStatusTable.getSubmitterUserName();

                afzWorkflowInquiryTable.Document            = workflowTrackingStatusTable.Document;

                if(actionTakenByName)

                    afzWorkflowInquiryTable.ActionTakenBy   = actionTakenByName;

                else

                    afzWorkflowInquiryTable.ActionTakenBy   = workflowTrackingTable.User;

                afzWorkflowInquiryTable.TrackingType        = workflowTrackingTable.TrackingType;

                afzWorkflowInquiryTable.Context             = workflowTrackingTable.TrackingContext;

                afzWorkflowInquiryTable.CompanyName         = workflowTrackingStatusTable.ContextCompanyId;

                afzWorkflowInquiryTable.Comment             = workflowCommentTable.Comment;

                afzWorkflowInquiryTable.TrackingMessage     = workflowCommentTable.TrackingMessage;

                afzWorkflowInquiryTable.Name                = workflowTrackingTable.Name;

                afzWorkflowInquiryTable.DocumentRecId       = workflowTrackingStatusTable.ContextRecId;

                afzWorkflowInquiryTable.insert();

                ttscommit;

            }

                        

        }



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Get only last approver detail: - 


 select workflowTrackingStatus order by CreatedDateTime desc

            where workflowTrackingStatus.ContextTableId == tableNum(purchtable)

            && workflowTrackingStatus.ContextRecId == purchtable.recid

            && workflowTrackingStatus.TrackingStatus == WorkflowTrackingStatus::Completed

            join workflowTrackingTable order by CreatedDateTime desc

            where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId

            && workflowtrackingtable.TrackingContext == workflowtrackingcontext::WorkItem

            && workflowTrackingTable.TrackingType == WorkflowTrackingType::Approval

            join userInfo

            where userInfo.id == workflowTrackingTable.User;


        //_purchaseOrderHeader.User =   HcmWorker::findByPerson(DirPersonuser::find(currentUserId).PersonParty).name();


        _purchaseOrderHeader.User =   UserInfoHelp::userName(workflowTrackingTable.User);

        _purchaseOrderHeader.UserPrintedBy =  UserInfoHelp::userName(curUserId());

        _purchaseOrderHeader.UserOriginator =  UserInfoHelp::userName(purchtable.CreatedBy);

        

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


SQL Workflow Approval code

select * from workflowTrackingStatusTable a -- order by createdDateTime Asc
inner join WorkflowTrackingTable b
on a.RecId = b.WorkflowTrackingStatusTable
and a.TrackingStatus = 1
and a.ContextRecId = 5637145328 --(PurchTable/ PurchReqTable RecID)
and a.ContextTableId = 20050 --(PurchTable/ PurchReqTable TableId)
and b.TrackingType = 4
and b.trackingContext = 5
order by a.createdDateTime, b.createdDateTime Asc


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SQL Get Table ID

select * from SysTableIdView where Name = 'PURCHTABLE'


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


No comments:

Post a Comment