我有一个小问题。 通常在netsuite中,如果我们创建一个父矩阵项,并且同时创建六个子矩阵项,并且如果我们更新任何子矩阵项的matrixoptions,则更改也会反映在父矩阵项中 我试图通过脚本执行相同的操作,但是我面临的问题是我的代码,请帮助我
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/record'],
function(record) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request - Encapsulation of the incoming request
* @param {ServerResponse} context.response - Encapsulation of the Suitelet response
* @Since 2015.2
*/
function onRequest(context) {
try{
var clrArray =["red","green","yellow"];
var LsArray=["Small","Medium","Large"];
var k=0;
var Parent = record.create({
type: record.Type.INVENTORY_ITEM,
// id: 28405,
});
Parent.setValue({
fieldId: 'matrixtype',
value:'PARENT' ,
});
Parent.setValue({
fieldId: 'itemid',
value:'siyaram2' ,
});
Parent.setValue({
fieldId: 'subsidiary',
value:1,
});
Parent.setValue({
fieldId: 'taxschedule',
value:1,
});
Parent.setValue({
fieldId: 'custitem44',
value: 1
});
/*Parent.setValue({
fieldId: 'custitem83',
value:1,
});*/
var parentid = Parent.save({
ignoreMandatoryFields: true
});
log.debug('parent id is',parentid);
}
catch(error)
{
log.error(error);
}
try{
//for(i=0;i<clrArray.length;i++)
// for(j=0;j<LsArray.length;j++)
// {
var Child = record.create({
type: record.Type.INVENTORY_ITEM,
});
Child.setValue({
fieldId: 'itemid',
value:k++ ,
});
Child.setValue({
fieldId: 'matrixtype',
value:'CHILD' ,
});
Child.setValue({
fieldId: 'parent',
value:parentid ,
});
Child.setValue({
fieldId: 'taxschedule',
value:1 ,
});
/*Child.setValue({
fieldId: 'matrixoptioncustitem44',
value:1 ,
});*/
Child.setValue({
fieldId: 'matrixoptioncustitem44',
value: 3
});
var childId = Child.save({
ignoreMandatoryFields: true
});
log.debug('child is',childId)
// }
var childreload=record.load({
type: record.Type.INVENTORY_ITEM,
id: childId
});
var beforeset=childreload.getValue({fieldId:'matrixoptioncustitem44'});
var setvalue =childreload.setValue({fieldId:'matrixoptioncustitem44',value:2});
log.debug('value is',beforeset);
log.debug('setvalue is',setvalue);
var saved = Child.save({
ignoreMandatoryFields: true
});
log.debug('saved is',saved);
}
catch(error)
{
log.error({title:'child error',details:error});
}
}
return {
onRequest: onRequest
};
});
我已经创建了父矩阵项和chil矩阵项,并试图通过更改子记录的matrixitemoptions来更新子矩阵项,但是我遇到了这样的错误:
{"type":"error.SuiteScriptError","name":"THIS_RECORD_HAS_ALREADY_BEEN_CREATED_TO_PREVENT_CREATING_A_DUPLICATE_THIS_REQUEST_HAS_BEEN_CANCELLED","message":"This record has already been created. To prevent creating a duplicate, this request has been cancelled.","stack":["anonymous(N/serverRecordService)","onRequest(/SuiteScripts/MBL FEASIBILITY.js:117)"],"cause":{"type":"internal error","code":"THIS_RECORD_HAS_ALREADY_BEEN_CREATED_TO_PREVENT_CREATING_A_DUPLICATE_THIS_REQUEST_HAS_BEEN_CANCELLED","details":"This record has already been created. To prevent creating a duplicate, this request has been cancelled.","userEvent":null,"stackTrace":["anonymous(N/serverRecordService)","onRequest(/SuiteScripts/MBL FEASIBILITY.js:117)"],"notifyOff":false},"id":"","notifyOff":false}
答案 0 :(得分:0)
根据错误消息(和您的上面的代码),您尝试使用相同的矩阵组合制作子矩阵项,即所有具有 matrixoptioncustitem44 值的子项2 。 例如。就像T恤一样,您的父矩阵项目及其所有子矩阵项目的尺寸均相同。 这是无效的,因为子矩阵的大小应不同(按照上面的示例)。