Skip to main content

X++ code to auto submit purchase order to workflow in D365FO

In this post we will view the code to auto submit purchase order that is draft status to workflow. Please note in order to enable workflow necessary setup, workflow configuration and activation is required.
Created a runnable class and added below code for auto-submission of purchase order.
class PurchTableAutoSubmission
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
        PurchTable	purchTable;
        str			comment;
		select firstonly purchTable
            where purchTable.DocumentState == VersioningDocumentState::Draft;

        comment = strFmt("Purchase order %1 submitted to workflow by batch process", purchTable.PurchId);

		if (purchTable.checkFullyDistributedAndQualified())
            purchTable.submitToWorkflow(workflowTypeStr(PurchTableTemplate), comment, false);

            if (purchTable.DocumentState == VersioningDocumentState::InReview)
                Info(strFmt("Purchase order %1 submitted to workflow", purchTable.PurchId));

Chaitanya Golla


*This post is locked for comments