I have a script that currently runs aftersubmit on a custom record. I have many records that need to be updated and I don't want to open each one in edit mode then save to get the script running. Instead I want to run a Scheduled Script that looks at a search that has the records with empty fields. I then want the script edit all of the results so all of the records are up to date.
Here are the steps needed:
- Create a saved search for all custom product records with a specific field as null
- Load the search on the script and loop through each result.
- Load each record and make the necessary changes per record that is pulled up.
Here is my script so far and the error I am getting:
function red()
{
nlapiLogExecution('DEBUG', 'Start');
var searchresults = nlapiLoadSearch('customrecord_product','customsearch1150');
for(var i =null; i < searchresults.length; i++);
{
var searchresult = searchresults[i];
(17) var z=nlapiLoadRecord(241,searchresult.getId());
var x=searchresult.getFieldValue('custrecord_product_daysinservice');
searchresult.setFieldValue('custrecord_product_years_inservice_bd', x);
nlapiSubmitRecord (z);
return true;
nlapiLogExecution('DEBUG', 'End');
custrecord_product, i ++
}
}
ERROR: TypeError: Cannot call method "getId" of undefined (lifetime update.js$190271#17)