Saturday, February 16, 2019

Pre-populate Field Value on a Related Record using Go To Record action


When using Go To Record action, it is required to define a Record Type to which record the user will be redirected once this workflow action was triggered. We could then have the option to set field values on the destination record if we haven't set the ID field.

Optionally, we could set a value from the ID field if we wanted to redirect the user to an existing record. However, it would not let us set any of the fields on the destination record. The reason behind is that we really can't set field values on existing records on Before Record Load. This is common for both Set Field Value and Go To Record actions.

Fortunately, there is an alternate solution to be able to set field values on existing records when using Go To Record action. We have to use Custom Action which will update the field on the related record. Then use Go To Record to really go to the related record. This way, the user will be navigated to the related record where the field will already have been updated.

Scenario: User is selecting a related Work Order record from a Purchase Order. After saving, they wanted to be redirected to the specified Work Order record with the values set from Purchase Order record.

To test this, we have to create a custom Transaction Body Field, Workflow Action Script, and Workflow:

1. Create a new Transaction Body Field by going to Customization > Lists, Records, & Fields > Transaction Body Fields > New

Label: Work Order #

Type: List/Record

List/Record: Transaction

Store Value: Yes

- Applies To

Purchase: Yes

- Sourcing & Filtering

Filter Using: Type

Value Is: Work Order

2. Create a Workflow Action Script and deploy it to Purchase Order record from  Customization > Scripting > Scripts > New > Workflow Action

Name: Set WO field

Function: setMemoGOTO

function setMemoGOTO()


var newRec =nlapiGetNewRecord();

var value1 = newRec.getFieldValue('custbody27');

var value2 = newRec.getFieldValue('memo');

nlapiLogExecution('debug', 'value1 - value2', value1 + ' - ' + value2);


var loadRec = nlapiLoadRecord('workorder', value1);

loadRec.setFieldValue('memo', value2);


return value1;

return value2;



3. Create a new Workflow by navigating to  Customization > Scripting > Workflows > New

* Workflow Summary

Name: Set WO field from PO

Record Type: Transaction

Sub Types: Purchase Order

Release Status: Released/Testing

Enable Logging: Yes

Initiation: On Create / On Update

Trigger Type: Before Record Submit

* Workflow State 1

Name: Custom Action

            * Workflow Action 1

            Type: Custom Action: Set WO field

            Trigger On: Before Record Submit

            * Workflow Transition

            To: Go to WO

            Transition On: After Record Submit

* Workflow State 2

Name: Go to WO

            * Workflow Action 1

            Type: Go To Record

            Trigger On: After Record Submit

            Record Type: Work Order

            ID: Work Order #

Now that we have all these setup, let's try to trigger the workflow by updating a Purchase Order record. We have to set a value for the Memo field and the Work Order # field so there would be a value that could be captured by our workflow action script.

After clicking on the Save button, you will be redirected to Work Order #1 with the Memo field value of Test Memo from Memo field on Purchase Order record.

No comments:

Post a Comment