I have a SuiteScript 1.0 script where I'm trying to update a field on all records returned by a saved search. Unfortunately, I keep getting 'The record is not a valid object' error. I'm trying to load the record with the line below:
var item = nlapiLoadRecord(res.getRecordType(), intid);
intid is the internal id of the item record (I have this outputting this to a debug message, so I know it's correct). I've tried hard coding things like 'inventoryitem' or 'assemblyitem' but I get the same error either way. All my code is below in case I'm making a mistake elsewhere.
function SyncBCID(type) {
var search = nlapiLoadSearch('item','customsearch_script_itm_meta_fields');
var results = search.runSearch();
//nlapiLogExecution('DEBUG', '-- Start --');
results.forEachResult(function(res){
var intid = res.getValue('internalid');
var bcid = res.getValue('custrecord_celigo_bg_siim_productid', "custrecord_celigo_bg_siim_nsid");
var sku = res.getValue('custitem_amazon_product_code');
var rectype = res.getRecordType();
nlapiLogExecution('DEBUG', 'BC ID: '+bcid+' SKU: '+sku+' Internal ID: '+intid+' Record Type: '+rectype);
try {
var item = nlapiLoadRecord(res.getRecordType(), intid);
item.setFieldValue('custitem_bc_int_id', bcid, false);
nlapiSubmitRecord(res.getRecordType(), true);
} catch(e) {
var errMsg = e.getDetails();
if (errMsg != 'Danger Will Robinson') {
nlapiSendEmail(17800280, '[email protected]', 'Error with updating BC ID', 'Error updating BC ID for '+sku+'. Error: '+errMsg);
nlapiLogExecution('ERROR', e.getCode(), errMsg);
}
}
return true;
});
//nlapiLogExecution('DEBUG', '-- End --');
}
Any kick in the right direction would be greatly appreciated.
I have a SuiteScript 1.0 script where I'm trying to update a field on all records returned by a saved search. Unfortunately, I keep getting 'The record is not a valid object' error. I'm trying to load the record with the line below:
var item = nlapiLoadRecord(res.getRecordType(), intid);
intid is the internal id of the item record (I have this outputting this to a debug message, so I know it's correct). I've tried hard coding things like 'inventoryitem' or 'assemblyitem' but I get the same error either way. All my code is below in case I'm making a mistake elsewhere.
function SyncBCID(type) {
var search = nlapiLoadSearch('item','customsearch_script_itm_meta_fields');
var results = search.runSearch();
//nlapiLogExecution('DEBUG', '-- Start --');
results.forEachResult(function(res){
var intid = res.getValue('internalid');
var bcid = res.getValue('custrecord_celigo_bg_siim_productid', "custrecord_celigo_bg_siim_nsid");
var sku = res.getValue('custitem_amazon_product_code');
var rectype = res.getRecordType();
nlapiLogExecution('DEBUG', 'BC ID: '+bcid+' SKU: '+sku+' Internal ID: '+intid+' Record Type: '+rectype);
try {
var item = nlapiLoadRecord(res.getRecordType(), intid);
item.setFieldValue('custitem_bc_int_id', bcid, false);
nlapiSubmitRecord(res.getRecordType(), true);
} catch(e) {
var errMsg = e.getDetails();
if (errMsg != 'Danger Will Robinson') {
nlapiSendEmail(17800280, '[email protected]', 'Error with updating BC ID', 'Error updating BC ID for '+sku+'. Error: '+errMsg);
nlapiLogExecution('ERROR', e.getCode(), errMsg);
}
}
return true;
});
//nlapiLogExecution('DEBUG', '-- End --');
}
Any kick in the right direction would be greatly appreciated.
Share Improve this question asked Feb 7 at 18:56 JohnJohn 692 silver badges14 bronze badges1 Answer
Reset to default 1Should be
nlapiSubmitRecord(item, true);
BTW unless you know for sure that you will only have a few rows returned at some point you are going to run into a governance outage.
Whatever is currently triggering your current script should likely try to trigger a map/reduce script to avoid governance outages.