I am attempting to create a sales order using a RESTlet.
I am passing in information similar to the example listed in the help files.
The script I am using is:function createRecord(datain)
{
var err = new Object();
// Validate if mandatory record type is set in the request
if (!datain.recordtype)
{
err.status = "failed";
err.message= "missing recordtype";
return err;
}
var record = nlapiCreateRecord(datain.recordtype);
for (var fieldname in datain)
{
if (datain.hasOwnProperty(fieldname))
{
if (fieldname != 'recordtype' && fieldname != 'id')
{
var value = datain[fieldname];
if (value && typeof value != 'object') // ignore other type of parameters
{
record.setFieldValue(fieldname, value);
nlapiLogExecution('DEBUG','fieldname='+fieldname);
}
}
}
}
var recordId = nlapiSubmitRecord(record);
nlapiLogExecution('DEBUG','id='+recordId);
var nlobj = nlapiLoadRecord(datain.recordtype,recordId);
// return nlobj;
return "Setup Complete";
}
my json string is
{ "total":64.04,"altshippingcost":5.67,"shipcomplete":false,"discounttotal":0.00,"entity":"10","salesrep":"7","ccapproved":false,"department":"5" ,"lastmodifieddate":"7/19/201211:34pm","istaxable":true,"tobefaxed":false,"altsalestotal":0.00,"getauth":false,"tobeprinted":false,"shippingcost":5.67,"recordtype":"salesorder","trandate":"7/19/2012","location":"5","startdate":"7/19/2012","item":[{"account_id":111,"company_id":10, "isclosed":false,"fromjob":false,"amount":44.96,"rate":44.96,"price":"2","istaxable":false,"item_id":"4400","quantity":1,"isestimate":false}]}
I am receiving the following error:
Account: xxxxxxxx
Environment: SandBox
Date & Time: 7/19/2012 2:18 pm
Execution Time: 1.77s
Script Usage: 10
Script: RestTest
Type: RESTlet
Function: createRecord
Error: USER_ERROR
You must enter at least one line item for this transaction.
Stack Trace: createRecord(tesetrestlet.js:29)
restletwrapper(null$lib:4)
I have an item listed in my string, but there appears to be an issue with the item or with the contents of the item.
Item:
"item":[{"account_id":111,"company_id":10, "isclosed":false,"fromjob":false,"amount":44.96,"rate":44.96,"price":"2","istaxable":false,"item_id":"4400","quantity":1,"isestimate":false}]}
I have tried several iterations and at this point it appears that I am stuck.
If there is an error with the formatting of the item could that cause the error I am seeing?
The help files and examples are very limited, any help or additional examples would be greatly appreciated.