Steps to create Custom Field.
1. Customize the custom record type. (Customization> Lists, Records, & Fields > Record Types)
2. Add a new field and set the following details.
Steps to create User Event Script.a. Label - "Opp Sales Order"
b. Type - Multiple Select
c. List/Record - Transaction
d. Store Value - Checked
1. Create a User Event script. (Customization > Scripting > Scripts > New)
2. Load the sample script below and set the function to the "Before Submit Function".
function beforeSubmit(type) {
nlapiLogExecution('DEBUG', 'Opp Related Sales Order', 'Start');
// Check if 'custrecord34' contains a value. 'custrecord34' is the field that contains the opportunity.
if (nlapiGetFieldValue('custrecord34') != null || nlapiGetFieldValue('custrecord34') != '') {
// Search for sales order that was created from the opportunity
var arrSearchFilters = new Array();
arrSearchFilters[0] = new nlobjSearchFilter('createdfrom', null,'anyof', nlapiGetFieldValue('custrecord34'));
arrSearchFilters[1] = new nlobjSearchFilter('mainline', null, 'is', 'T');
var arrSearchColumns = new Array();
arrSearchColumns[0] = new nlobjSearchColumn('internalid');
var arrSearchResults = nlapiSearchRecord('salesorder', null, arrSearchFilters, arrSearchColumns);
var values = new Array(); // Initialize an array that would contain the values of the internal ids of the sales orders
for ( var i in arrSearchResults) {
var searchResults = arrSearchResults[i];
nlapiLogExecution('DEBUG', 'test', searchResults.getValue('internalid'));
values[i] = searchResults.getValue('internalid');
}
nlapiSetFieldValue('custrecord35', values); // custrecord35 is the internal id of the multi select custom field
}
}
No comments:
Post a Comment