Skip to main content

Notifications

Announcements

No record found.

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

Hi,
 
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())
        {
            ttsbegin;
            purchTable.selectForUpdate(true);
            purchTable.submitToWorkflow(workflowTypeStr(PurchTableTemplate), comment, false);
            ttscommit;

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

}
 
Regards,
Chaitanya Golla

Comments

*This post is locked for comments