RE: Unexpected Error on Inventory Item Creation in Restlet
I have a restlet written in Suitescript 1.0 (haven’t had the chance to convert it yet). I use this to create orders and customers and pull records in general. I’m using it for the first time to create items, but upon the execution of nlapiSubmitRecord it’s returning UNEXPECTED_ERROR. Has anyone dealt with this before or even have successful code with item creation. The most I can find is that possibly another onsubmit record may be interfering with this, but I’m not sure. Some guidance would be much appreciated!
Thanks
Do y’all want the code of the restlet or where I’m calling the restlet. I’m calling the restlet through an automation software actually so I’m just providing the headers, endpoint, and body data.
I actually have an intermediate API set up that I call that then calls netsuite. The automation software calls the intermediate server which hits netsuite and returns the data.
I have this set up to get and post contacts and sales orders.
Below is the restlet code. I don’t have the code per se to share it where I’m making the call.
// Create a standard NetSuite recordfunction createRecord(datain){varerr=newObject();// Validate if mandatory record type is set in the requestif (!datain.recordtype){err.status="failed";err.message="missing recordtype";returnerr;}varrecord=nlapiCreateRecord(datain.recordtype);nlapiLogExecution('DEBUG','title','record='+JSON.stringify(record));for (varfieldnameindatain){if (datain.hasOwnProperty(fieldname)){if (fieldname!='recordtype'&&fieldname!='id'&&fieldname!=='itemid'){varvalue=datain[fieldname];if (value&&typeofvalue!='object'){ // ignore other type of parametersrecord.setFieldValue(fieldname, value);nlapiLogExecution('DEBUG', 'title',"test"+record);} else if (value && fieldname && typeof value == 'object'){ // process line item objectsvarname=fieldnamefor (varitemobjectinvalue){record.selectNewLineItem(fieldname);varlineitemobject=value[itemobject];for (varlineitemfieldnameinlineitemobject ){varlineitemfieldvalue=lineitemobject[lineitemfieldname];record.setCurrentLineItemValue(fieldname,lineitemfieldname,lineitemfieldvalue);}record.commitLineItem(fieldname);}}}}}nlapiLogExecution('DEBUG','Hey','this working? line 123');if(datain.addressBook){varaddressBookDataList=datain.addressBooknlapiLogExecution('DEBUG', JSON.stringify(datain.addressBook.addressbookaddress));addressBookDataList.forEach(function (data) {record.selectNewLineItem('addressbook');nlapiLogExecution('DEBUG', JSON.stringify(data.addressbookaddress));// record.setCurrentLineItemValue('addressbook', 'attention', data.attention);record.setCurrentLineItemValue('addressbook', 'addressee', data.addressbookaddress.addressee);record.setCurrentLineItemValue('addressbook', 'addr1', data.addressbookaddress.addr1);record.setCurrentLineItemValue('addressbook', 'addr2', data.addressbookaddress.addr2);// record.setCurrentLineItemValue('addressbook', 'addr3', data.addr3);record.setCurrentLineItemValue('addressbook', 'city', data.addressbookaddress.city);record.setCurrentLineItemValue('addressbook', 'state', data.addressbookaddress.state);record.setCurrentLineItemValue('addressbook', 'zip', data.addressbookaddress.zip);record.setCurrentLineItemValue('addressbook', 'country', data.addressbookaddress.country.internalid);record.setCurrentLineItemValue('addressbook', 'label', 'shipping address');record.commitLineItem('addressbook');})}if (datain.recordtype==='returnauthorization'&&datain.itemid) {record.selectNewLineItem('item');record.setCurrentLineItemValue('item','item', datain.itemid);record.commitLineItem('item');}nlapiLogExecution('DEBUG','Hey',JSON.stringify(record));varrecordId=nlapiSubmitRecord(record, true, true);nlapiLogExecution('DEBUG','id='+recordId);varnlobj=nlapiLoadRecord(datain.recordtype,recordId);nlapiLogExecution('DEBUG','execution: '+nlobj);returnnlobj;}
battk
Share the code, preferably with hardcoded variables