Sunday, April 21, 2019

Add Sales Rep Field in Transaction Body Field from Sales Order on Work Order using Created From Field

If a Work Order was created from a Sales Order, the Work Order will show the Sales Order Number in the Created From field.
A Transaction Body Field with the purpose to get the Sales Rep of the Sales Order on the Work Order has been created with the following details:

Type = List/Record
Store Value = T
Applies To = Work Order
Under Sourcing & Filtering:
Source List = Created From
Source From = Sales Rep

Actual Result when creating a Work Order from Sales Order: The Sourcing&Filtering of Created From:Sales Rep doesn't populate on the Work Order.

Adding fields from the linked Sales Order in Transaction Body Fields using Sourcing&Filtering, Source List = Created From, Source From = Sales Rep(or any other field) is not possible for the moment. Defect 167043 has been logged for the same.

Desired result can be achieved through script:

  1. Remove the Sourcing&Filtering for the Transaction Body Field defined
  2. Create a User Event Script with Before Submit Function to retrieve Sales Rep value from Sales Order and set it on the Work Order:
    function updateWO_beforeSubmit(type){     //retrieve the Sales Order ID from which the WO has been created	 var createdFrom = nlapiGetFieldValue('createdfrom');	 	 if (createdFrom != null)		 {		 //load the Sales Order details		 var order = nlapiLoadRecord('salesorder', createdFrom);		 //get the SO Sales Rep		 var salesRep = order.getFieldValue('salesrep');		 //set the value of the Sales Rep on the current WO		 nlapiSetFieldValue( 'custbody_sales_rep', salesRep);		 }		 }

The script needs to be deployed on Work Order record so that the Sales Rep to be set on the linked Work Order right before saving it upon creation of Sales Order.

Detailed steps on creating and deploying scripts in NetSuite can be found in SuiteAnswers Article Running Scripts in NetSuite Overview.


No comments:

Post a Comment