当我向Netsuite发送休息电话并通过RESTlet创建新的销售订单时,我发现如果销售订单“'字段仅包含库存项目。但是,当销售订单包含assemblyitem或kit / package项时,nlapiSubmitRecord()函数将返回null,并且不会创建销售订单。 (也没有错误) 有人可以告诉我原因吗?谢谢!
用于创建新销售订单的我的RESTlet功能如下:
function createSalesorder(datain) {
// init message and sales order obj
var message = new Object();
var record = nlapiCreateRecord('salesorder');
// check if the sales order already exists in Netsuite
if(!datain['otherrefnum']){
message.status = 'failed',
message.message = 'missing Customer P.O.';
return message;
} else {
var filters = new Array();
var columns = new Array();
filters.push(new nlobjSearchFilter('otherrefnum', null, 'equalto', datain['otherrefnum']));
filters.push(new nlobjSearchFilter('entity', null, 'is', datain['entity']));
// columns.push(new nlobjSearchColumn('otherrefnum', null, null));
var search = nlapiSearchRecord(datain.recordtype, null, filters, columns);
if(search && search.length>0){
message.status = 'duplicated',
message.id = search[0].id;
return message;
}
}
// check input data has required fields
if(!datain['item']){
message.status = 'failed';
message.message = 'missing item';
return message;
}
if(!datain['entity']){
message.status = 'failed';
message.message = 'missing customer id';
return message;
}
// init fields with default values
if(!datain['custbody_shipping_reason']){
record.setFieldValue('custbody_shipping_reason',1);
}
if(!datain['custbody_order_type']){
record.setFieldValue('custbody_order_type',1);
}
if(!datain['shipmethod']){
record.setFieldValue('shipmethod', 4304);
}
if(!datain['location']){
record.setFieldValue('location', 21);
}
if(!datain['istaxable']){
record.setFieldValue('taxitem', -8);
}
// load data input
for(var fieldname in datain){
switch(fieldname){
case 'recordtype':
case 'type':
case 'id':
break;
case 'istaxable':
record.setFieldValue(fieldname, datain[fieldname]);
if(datain[fieldname] == 'T') record.setFieldValue('taxitem', 2908);
else record.setFieldValue('taxitem', -8);
case 'item':
for(var i = 0; i < datain[fieldname].length; i++){
for(var itemfield in datain[fieldname][i]){
record.setLineItemValue('item', itemfield, i+1, datain[fieldname][i][itemfield]);
}
}
break;
default:
record.setFieldValue(fieldname, datain[fieldname]);
break;
}
}
// submit record
var recordID = nlapiSubmitRecord(record, true);
nlapiLogExecution('DEBUG', 'Create a new salesorder, id = '+recordID);
// return results
message.status = 'create';
message.id = recordID;
var order_entity = nlapiLoadRecord('salesorder', message.id);
message.refid = order_entity.getFieldValue('tranid');
return message;
}
更新1:我试图在Netsuite调试器中运行相同的代码,结果是成功编写了销售订单,除此之外还出现了警告:
warning Items on this line have been drop shipped or special ordered. Are you sure you want to modify it?
不确定这是否会阻止我在生产模式下正确保存销售订单。
答案 0 :(得分:0)
我认为这是因为assemblyitem或kit / package项目具有不同的必填字段,因此您应该手动为它们添加值。
请尝试让我知道这些问题。
答案 1 :(得分:0)