I have a scheduled script that I occasionally use to resend invoices via email. The script calls up a custom record that has all of the invoice I want to resend the invoices. From the invoice, I just have to set a field (email invoice) to true which then triggers a workflow to email the invoice.
My problem is that I get this RCRD_UNEDITABLE error in my log, not sure why as I have another script that uses the same process without an errors. Here's my code, perhaps I have a case of tunnel vision and not seeing it clearly.
function emailinv() { var stLoggerTitle = 'emailinv'; try { var columns = new Array(); columns.push(new nlobjSearchColumn('name')); var results = nlapiSearchRecord('customrecord_hub_resend_inv_email',null,null,columns); if (results) { var invnum; var rec; for (var i = 0; i < results.length; i++){ invnum = results[i].getValue('name'); nlapiLogExecution('DEBUG',stLoggerTitle,'Invoice ID ' + invnum); rec = nlapiLoadRecord('invoice',invnum); rec.setFieldValue('custbody_hub_email_invoice','T',true); nlapiSubmitRecord(rec); nlapiLogExecution('DEBUG',stLoggerTitle,'Invoice # ' + invnum + ' resend email triggered.'); } } } catch (error) { if (error.getDetails != undefined) { nlapiLogExecution('ERROR','Process Error',error.getCode() + ': ' + error.getDetails()); //throw error; } else { nlapiLogExecution('ERROR','Unexpected Error',error.toString()); throw nlapiCreateError('99999', error.toString()); } } }//end functionAny idea what I'm doing wrong?Here's another set of code that is working fine. The only difference is this set of code is on a custom record. function sendReminders() { var stLoggerTitle = 'sendReminders'; var tdate = new Date(); var mydate = tdate.getMonth() + 1 + '/' + tdate.getDate() + '/' + tdate.getFullYear(); nlapiLogExecution('DEBUG',stLoggerTitle,'Starting for ' + mydate); try { var recid; //get the record id var artrec; //load the art record var appvia; //determine appvia field //get the list of sales art proof records that have no approval status and have business day 1 field values of today var fltra = new Array(); fltra.push(new nlobjSearchFilter('custrecord_hub_bus_day_1',null,'on',mydate)); var artreca = nlapiSearchRecord('customrecord_hub_so_art_proof',230, fltra, null); if (artreca){ nlapiLogExecution('DEBUG',stLoggerTitle,'Sales Art Proof Reminders Business Day 1 returned ' + artreca.length + ' records.'); for(var a = 0; a < artreca.length; a++){ recid = artreca[a].getId(); if (!isEmpty(recid)){ //load the record artrec = nlapiLoadRecord('customrecord_hub_so_art_proof',recid); //get the approve via field value appvia = artrec.getFieldValue('custrecord_hub_appr_via'); if (appvia == 1 || appvia == 2){//appvia 1 is "Web" //set the reminder 1 field to true artrec.setFieldValue('custrecord_reminder1','T',true); //setting the reminder 1 field to true kicks off the send proof work flow. nlapiSubmitRecord(artrec); nlapiLogExecution('DEBUG',stLoggerTitle,'Art Proof record ' + recid + ', reminder 1 triggered.'); } else{//app via is not web or email artrec.setFieldValue('custrecord_hub_art_proof_fol_up_stat',6,false); //6 is send customer reminder 1. nlapiSubmitRecord(artrec); nlapiLogExecution('DEBUG',stLoggerTitle,'Art Proof record ' + recid + ', follow up status set to send reminder 1.'); }//end else app via is not web }//recid is not empty else{ nlapiLogExecution('DEBUG',stLoggerTitle,'Sales Art Proof Reminders Business Day 1, return record # ' + a + ' had no record id.'); }//end else appvia is empty }//end for }//end if artreca else{ nlapiLogExecution('DEBUG',stLoggerTitle,'Sales Art Proof Reminders Business Day 1, end no records'); } break; }//end try catch (error) { if (error.getDetails != undefined) { nlapiLogExecution('ERROR','Process Error',error.getCode() + ': ' + error.getDetails()); throw error; } else { nlapiLogExecution('ERROR','Unexpected Error',error.toString()); throw nlapiCreateError('99999', error.toString()); } }//end catch }//end function function isEmpty(stValue) { if ((stValue == '') || (stValue == null) ||(stValue == undefined)) { return true; } return false; }