Как следует из названия, я пытаюсь сохранить клиента в NetSuite Record, но не могу этого сделать.
Дело в том, что мне нужно сохранить клиента с его адресом, но кажется, что адрес не проходит как простое значение, чтобы сказать это, вместо этого является массивом.
Это тело:
{
"recordtype":"customer",
"entityid":"John Doe",
"companyname":"ABC Inc",
"subsidiary":"1",
"email":"[email protected]",
"custentity_cseg_region":"3",
"addressbook":[
{
"addressbookaddress":{
"zip":"104-8315",
"country":{
"internalid":"JP",
"name":"Japan"
},
"addressee":"ABC Inc",
"city":"Tokyo",
"addr1":"1-1, 1-Chome",
"attention":"John Doe",
"override":false
},
"addressbookaddress_text":"Lorem ipsum dolor sit amet\nno putant tamquam his\nclita option utroque id quo, ne noster epicurei sed",
"defaultbilling":true,
"defaultshipping":true,
"isresidential":false,
"label":"1-1, 1-Chome"
}
]
}
Записи сохраняются, но адрес не принимается.
Так выглядит SuiteScript.
function getRecord(datain) {
return nlapiLoadRecord(datain.recordtype, datain.id); // e.g recordtype = "customer", id = "769"
}
function createRecord(datain) {
var err = new Object();
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') {
record.setFieldValue(fieldname, value);
}
}
}
}
nlapiLogExecution('DEBUG', 'zip = ' + datain.zip);
record.selectNewLineItem('addressbook');
record.setCurrentLineItemValue('addressbook', 'attention', datain.attention);
record.setCurrentLineItemValue('addressbook', 'addressee', datain.companyname);
record.setCurrentLineItemValue('addressbook', 'addr1', datain.addr1);
record.setCurrentLineItemValue('addressbook', 'addr2', datain.addr2);
record.setCurrentLineItemValue('addressbook', 'addr3', datain.addr3);
record.setCurrentLineItemValue('addressbook', 'city', datain.city);
record.setCurrentLineItemValue('addressbook', 'state', datain.state);
record.setCurrentLineItemValue('addressbook', 'zip', datain.zip);
record.setCurrentLineItemValue('addressbook', 'country', 'US');
/*record.setCurrentLineItemValue('addressbook', 'country', datain.country);*/
record.setCurrentLineItemValue('addressbook', 'label', 'billing address');
record.commitLineItem('addressbook');
var recordid = nlapiSubmitRecord(record);
nlapiLogExecution('DEBUG', 'id = ' + recordid);
var nlobj = nlapiLoadRecord(datain.recordtype, recordid);
return nlobj;
}
@erictgrubaugh Я только что добавил файл.
В соответствии с вашим объектом JSON запроса вам необходимо обновить код RESTlet примерно так, как показано ниже.
function createRecord(datain) {
var err = new Object();
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') {
record.setFieldValue(fieldname, value);
}
}
}
}
var addressBookDataList = datain.addressbook;
// since addressbook is an array
// loop through the array and create/set address records on Customer
addressBookDataList.forEach(function (data) {
record.selectNewLineItem('addressbook');
record.setCurrentLineItemValue('addressbook', 'attention', data.attention);
record.setCurrentLineItemValue('addressbook', 'addressee', data.companyname);
record.setCurrentLineItemValue('addressbook', 'addr1', data.addr1);
record.setCurrentLineItemValue('addressbook', 'addr2', data.addr2);
record.setCurrentLineItemValue('addressbook', 'addr3', data.addr3);
record.setCurrentLineItemValue('addressbook', 'city', data.city);
record.setCurrentLineItemValue('addressbook', 'state', data.state);
record.setCurrentLineItemValue('addressbook', 'zip', data.zip);
record.setCurrentLineItemValue('addressbook', 'country', 'US');
/*record.setCurrentLineItemValue('addressbook', 'country', data.country);*/
record.setCurrentLineItemValue('addressbook', 'label', 'billing address');
record.commitLineItem('addressbook');
})
nlapiLogExecution('DEBUG', 'zip = ' + datain.zip);
var recordid = nlapiSubmitRecord(record);
nlapiLogExecution('DEBUG', 'id = ' + recordid);
var nlobj = nlapiLoadRecord(datain.recordtype, recordid);
return nlobj;
}
Как выглядит рестлет, создающий покупателя?