I am trying to create an inventory item in suitescript but I keep getting the following error Invalid reference key [null].
This code is called on an aftersubmit basis on a Custom record:
function setItem()
{
title = "test inventory item";
newRecord = nlapiCreateRecord('inventoryitem');
id = newRecord.getId();
newRecord.setFieldValue('itemid',"test inventory item");
type = newRecord.getRecordType();
newRecord.setFieldValue('cogsaccount',122);
newRecord.setFieldValue('assetaccount',121);
newRecord.setFieldValue('department',"Glasgow Opportunities");
newRecord.setFieldValue('class',"O.D.C : Training : Bespoke Training (Large Project");
newRecord.setFieldValue('purchasetaxcode',"Go:GO-na");
newRecord.setFieldValue('salestaxcode',"Go:GO-S");
debugTxt = "newRecord is "+newRecord+id+type;
nlapiLogExecution('DEBUG','<Before Load Script>',debugTxt);
taskNum = nlapiSubmitRecord(newRecord);
nlapiSetRedirectURL('RECORD', 'inventoryitem', taskNum, false);
}
The debug text returns a null for the record id and inventorytype for the record type - I know it is probably something simple but I cant get it to work - any help ?