Thursday, April 11, 2019

D365FO get workflow comment (submission, rejection, approval or any comment) X++

You can get workflow comment at any stage, be it from submission, approval, rejection or any other stage. There will be only one query for all of them with only change of an Enum WorkflowTrackingType value highlighed in the query below.

In this method , for example, the rejected comment of Purchase order workflow is fetched through query by filtering workflowTrackingTable.TrackingType with Rejection element of the enum.


private WorkflowComment getPORejectedWorkflowComment(PurchId _purchId)
{
        WorkflowTrackingTable           workflowTrackingTable;
        WorkflowTrackingStatusTable     workflowTrackingStatusTable;
        WorkflowTrackingCommentTable    workflowTrackingCommentTable;
        PurchTable                      purchTable;

        purchTable = PurchTable::find(_purchId);

        select ContextCompanyId, ContextTableId, ContextRecId from workflowTrackingStatusTable
        where workflowTrackingStatusTable.ContextCompanyId    == curext()
           && workflowTrackingStatusTable.ContextTableId      == purchTable.TableId
           && workflowTrackingStatusTable.ContextRecId        == purchTable.RecId
        join firstonly TrackingId, CreatedDateTime from workflowTrackingTable order by CreatedDateTime desc
            where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId
                && workflowTrackingTable.TrackingType == WorkflowTrackingType::Rejection
        join Comment from workflowTrackingCommentTable
            where workflowTrackingCommentTable.WorkflowTrackingTable == workflowTrackingTable.RecId;

        return workflowTrackingCommentTable.Comment;
    }

The enum WorkflowTranckingType has following elements, specifying which you can get the specific comment:






No comments:

Post a Comment