Saturday, March 30, 2019

Update related records in WorkFlow

Question:

User wants to update record related to record which is applied to workflow.

Answer:

Let's have a workflow running on Sales Order record type.
Related record should be linked with Sales Order record. For example like Customer record is linked to Sales Order.

How to link any Record type to Sales Order:
- add a new transaction body field at Customization > Lists, Records & Fields > Transaction Body Field > New
- under "Applies To" subtab check Sale checkbox
- under "Display" subtab choose subtab Field where should the field be displayed ("main" for main body section).
- set "Type" as "List/Record"
- select "List/Record" you would like to link

Then WorkFlow Action Script must be used to update related record.
To see how to create this script please check WorkFlow Action Script article.

Syntax can be similar to this sample:

// Get the ID of the record which is related
var relatedRecordId = nlapiGetFieldValue('field_id_with_related_record');

// Get Value of "memo" field for example
var memo = nlapiGetFieldValue('memo');

// Load, update and save related record and set any field(s) you like
var relatedRecord = nlapiLoadRecord('related_record_type_id',relatedRecordId);
relatedRecord.setFieldValue("field_id",memo);
var id = nlapiSubmitRecord(customerRecord, true);


No comments:

Post a Comment