Hello Everyone,
I need some help with this script. Basically we have a custom record for "Contracts" which is associated with a Sales Order. When that contract is within 45 days of expiration, a button appears on the Contract to Renew it which opens up a new quotation and brings in the values for the previous contract and the customer name from the contract record. Fairly simple and working properly. Now I would like to be able to bring over the line items that are "marked virtual" from the original sales order. This SO is referenced in the previous contract. The script I thought would work would be after field changes (my other script runs on pageinit that sets the values for the previous contracts), run a search with filters as internal id = the sales order id of the original sales order, mainline is F, and is virtual? = T. The only column returning is for the 'item' so I can push it to the new Quote and all of the fields should fill in automatically. I am getting an error saying my function is not defined and my debug log shows nothing. Here's the code:
function fieldchanged(name){
if(name == 'custbody_previous_contract'){
var PreviousContract = nlapiGetFieldValue('custbody_previous_contract');
if (PreviousContract != "" && PreviousContract != null) {
var soID = nlapiLookupField('customrecord_contracts', PreviousContract, 'custrecord_sales_order_number');
nlapiLogExecution('debug', 'SO ID', soID);
var Filters = new Array();
Filters[0] = new nlobjSearchFilter('internalid', null, 'anyof', soID);
Filters[1] = new nlobjSearchFilter('mainline', null, 'is', 'F');
Filters[2] = new nlobjSearchFilter('custcol_is_virtual', null, 'is', 'T');
var Columns = new Array();
Columns[0] = new nlobjSearchColumn('item');
var ItemResults = nlapiSearchRecord('salesorder', null, Filters, Columns);
nlapiLogExecution('debug', 'Search Results', ItemResults);
var Items = new Array();
for (var i = 0; ItemResults != null && i < ItemResults.length; i++) {
Items.push({
item: ItemResults[i].getValue(col[0])
});
}
return Items;
}
}
}
Any help or tips are very very much appreciated!