D365FO: Submit pending vendor invoice to workflow in X++

Purpose:

In this post we’re going to learn how can we submit a pending vendor invoice to approval workflow in X++.

Application:

Dynamics 365 for Finance and Operations

Business requirement:

Submit a pending vendor invoice to approval workflow in X++.

Solution:

We can use the code below to submit a pending vendor invoice to approval workflow.

Code

/// <summary>
/// Submits vendor invoice to workflow.
/// </summary>
public static void main(Args _args)
{
	WorkflowComment      workflowComment;
	TradeLineRefId       headerReference;
	VendInvoiceInfoTable vendInvoiceInfoTable;
	
	headerReference = "COMP-011202";
	workflowComment = "Auto submission to workflow.";
	vendInvoiceInfoTable = VendInvoiceInfoTable::findTableRefId(headerReference);

	if (vendInvoiceInfoTable)
	{
		try
		{
			VendInvoiceHeaderWorkflow::submitToWorkflow(vendInvoiceInfoTable, workflowComment);
		}
		catch (Exception::CLRError)
		{
			System.Exception interopException = CLRInterop::getLastException();
			error(strFmt("%1", interopException));
		}
		catch (Exception::Error)
		{
			error(strFmt("An error occured during the update."));
		}
	}
}

Leave a comment

Create a free website or blog at WordPress.com.

Up ↑