Updating the Submission Manager Method to Start the Workflow

By default, the submission method that is created by the Workflow Wizard is empty, so we need to add a little bit of code to tell the system what to do when the user clicks on the Submit button to initiate the workflows.

NOTE: This is part of the Developing a Product Approval Workflow in Dynamics AX 2012 blog series where we show how to develop a completely new workflow to manage the new product approval process. If you want to see all of the other posts in this series, click here.

How to do it…

To update the Submit method for the workflow to make it start the workflows running correctly, follow these steps:

  1. Open up the ProductApprovalWFType project, and from the Classes group, double click on the ProductApprovalSubmitManager class.
  2. This will open up the method browser, and you can select the main method.
  3. Update the main method to look like this:

    static
    public
    void main(Args args)

    {

    recId recId = args.record().RecId;

    WorkflowCorrelationId workflowCorrelationId;

    WorkflowTypeName workflowTypeName = workFlowTypeStr(ProductApproval);

    WorkflowComment note = “”;

    WorkflowSubmitDialog workflowSubmitDialog;

    InventTable InventTable;

    workflowSubmitDialog = WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());

    workflowSubmitDialog.run();

    if (workflowSubmitDialog.parmisClosedOK())

    {

    recId = args.record().RecId;

    InventTable = args.record();

    note = workflowSubmitDialog.parmWorkflowComment();

    try

    {

    ttsbegin;

    workflowCorrelationId = Workflow::activateFromWorkflowType(workflowTypeName,recId,note,NoYes::No);

    InventTable.ProductApprStatus = ProductApprStatus::Submitted;

    info(“Submitted to workflow”);

    ttsCommit;

    }

    catch (Exception::Error)

    {

    info(“Error on workflow activation.”);

    }

    }

    args.caller().updateWorkflowControls();

    }

  4. After you have updated the method, save it, and if there are any syntax errors, then you will be able to correct them here in the editor. When everything is fine, you can code out of the method editor.
  5. Just to be sure, save your project to make sure that there aren’t any other grammatical errors in the code.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: