- Customization > Scripting > Scripts > New : Restlet > function POST
function setRecord(data)
{
var retObj = createInvoice(data);
return JSON.stringify(retObj);
}
function createInvoice(data)
{
var record = nlapiCreateRecord('invoice');
var properties = {
'location': '',
'taxItem': '',
'itemList': ''
};
record.setFieldValue('customform', '116');
record.setFieldValue('entity', '8');
for (p in properties)
{
if (typeof data[p] == 'undefined')
{
return { 'error': 'Missing required field: ' + p };
}
var value = data[p];
if (p == 'itemList' && typeof value == 'object')
{
for (var itemobject in value)
{
record.selectNewLineItem('item');
var lineitemobject = value[itemobject];
for (var lineitemfieldname in lineitemobject)
{
var lineitemfieldvalue = lineitemobject[lineitemfieldname];
record.setCurrentLineItemValue('item', lineitemfieldname, lineitemfieldvalue);
}
record.commitLineItem('item');
}
}
else
{
record.setFieldValue(p, value);
}
}
var recordId = nlapiSubmitRecord(record);
return { internalId: recordId };
}
Restlet POST request sample (Also add the authorization and content-type headers):
- {"entity":"8","recordtype":"invoice","location":"1","taxItem":"CA-ALAMEDA","itemList":[{"item":"4","quantity":"1"}]}
*This is for SuiteScript version 1.0
Hi Could you please share sample code for INVOICE creation
ReplyDelete