Sunday, November 11, 2018

Create transaction records via the Workflow Manager

This article will address the current enhancement issue: 180033 to let the Workflow Manager have the ability to create any transaction records using the Create Record action. As an alternate solution, a custom workflow action script is created to create the transaction via scripting. Then, the created records Internal ID is returned to the workflow for further processing.

Sample Script:

function createSO()
{
     var so = nlapiCreateRecord('salesorder');
     so.setFieldValue('entity', 163);
     so.selectNewLineItem('item');
     so.setCurrentLineItemValue('item','item', 9); 
     so.setCurrentLineItemValue('item','quantity', '1');
     so.commitLineItem('item');
     var soID = nlapiSubmitRecord(so);
     return soID;
}    

The created record is returned so it can be used by the workflow. For more information in storing a returned value from a workflow action script, please refer to this article 'Storing a Return Value from a Custom Action Script in a Custom Field'. Since the returned value is an Integer, ensure that Return Type in the action script is also an Integer. Take note of the action script's name.

Now that you have the action script, you will now create the workflow.

1. Create a new workflow by navigating to  Customization > Workflow > Workflows > New.

2. Define the workflow
     a. Name = Create Sales Order
     b. Record Type = Employee
     c. Release Status = Released
     e. On Update = TRUE
     f. Trigger Type = Before Record Load
     g. Click Save.

3. Create an Instance custom field. On the workflow definition page, clicking the New Field button on the Fields tab. 
     a. Label = SO ID
     b. Type = Integer
     c. Store Value = TRUE
     d. Click Save.
* Take note of the ID of the created field.

4. To add a workflow state, click New State and set Name = Create SO Button, then hit Save.  

5. To create an action to the state, click on the Create SO Button state and click New Action. 
     a. Select Add Button.
     b. Trigger On = Before Record Load
     c. Label = Create SO
     d. Click Save. 

6. Add another state, and set it to Create An SO, then hit Save.

7. Call the action script within this state. Click the Create An SO state and hit New Action. 
     a. Select '<script name> (Custom)'. // This is the script name of the workflow action script you created earlier. The word Custom is appended.
     b. Trigger = On Entry.
     c. Store Result In = SO ID (Workflow) // workflow instance fields have 'Workflow' appended to it.
     d. Click Save.

8. Create a new transition. Select the Create SO Button state first. Click the New Transition button and then select the Create An SO state.
     a. Button = Create SO
     b. Click Save.

// The succeeding steps are optional. This is provided to show that the script has successfully created the transaction and it returned the ID back into the workflow.

8. Create another state and set the name to Set Internal ID and click Save.

9. To create an action to the state, click on the Create SO Button state and click New Action. 
     a. Select Set Field Value.
     b. Trigger On = Entry
     c. Field = Comments
     d. Formula: {custworkflow12} // This is the ID of the instance field.
     e. Click Save. 

10. Create another transition between the states Create An SO and Set Internal ID.

No comments:

Post a Comment