Workflow Action Script 2.0 to Set the Preferred Vendor when Creating an Assembly/Bill of Materials item

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. 

  1. 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
};

})

  1. Create a new Workflow Action Script 
  2. Navigate to Customization > Scripting > Scripts New 
  3. Select the JavaScript file from the drop-down list
  4. Click the Create Script Record button
  5. Set a Name, example: Preferred Vendor for Assembly Items
  6. Navigate to the Deployments sub tab Add a new line as follows:
  7. Under the Applies To column select Assembly/Bill of Materials
  8. Under the Deployed column mark the checkbox to YES
  9. Under the Status column select Released
  10. Click Save
  11. Create a new Workflow by navigating to Customization > Workflow > Workflows > New
  12. Set a Name.
  13. In the Record Type field, select Item.
  14. In the field Sub Types, select Assembly/Bill of Materials
  15. In the Initiation section, select On Create under Event Based
  16. Select All Types for Trigger Type
  17. Click the Save button.
  18. Then click the State 1 box and click the New Action button.
  19. Select the Workflow Action Script name from the Action list
  20. Then set Trigger OnAfter Record Submit
  21. Event Types: Create
  22. Click Save

Leave a comment

Your email address will not be published. Required fields are marked *