The user wants to create a Workflow Action Script to set the preferred Vendor when creating a new Assembly Item when the Multiple Vendor Feature is enabled in the account.
- Upload a new JavaScript (.js) file to the File Cabinet with the following code:
/**
- @NApiVersion 2.x
- @NScriptType WorkflowActionScript
*/
define([‘N/record’],function(record) {
function onAction(context){
var itemRec = context.newRecord;
var itemId = itemRec.id;
var item = record.load({
type: record.Type.ASSEMBLY_ITEM,
id: itemId
});
item.setSublistValue({
sublistId: 'itemvendor',
fieldId: 'vendor',
line:0,
value: 101
}); //value is a Vendor internal ID that you want to set as preferred
item.setSublistValue({
sublistId: 'itemvendor',
fieldId: 'preferredvendor',
line:0,
value: true
});
item.save();
return true;
}
return {
onAction: onAction
};
})
- Create a new Workflow Action Script
- Navigate to Customization > Scripting > Scripts New
- Select the JavaScript file from the drop-down list
- Click the Create Script Record button
- Set a Name, example: Preferred Vendor for Assembly Items
- Navigate to the Deployments sub tab Add a new line as follows:
- Under the Applies To column select Assembly/Bill of Materials
- Under the Deployed column mark the checkbox to YES
- Under the Status column select Released
- Click Save
- Create a new Workflow by navigating to Customization > Workflow > Workflows > New
- Set a Name.
- In the Record Type field, select Item.
- In the field Sub Types, select Assembly/Bill of Materials
- In the Initiation section, select On Create under Event Based
- Select All Types for Trigger Type
- Click the Save button.
- Then click the State 1 box and click the New Action button.
- Select the Workflow Action Script name from the Action list
- Then set Trigger On: After Record Submit
- Event Types: Create
- Click Save