【问题标题】:Updating matrix item options through suitescript通过suitescript更新矩阵项选项
【发布时间】:2018-09-14 06:54:26
【问题描述】:

我有一个小问题。 通常在 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
};

});

我已经创建了父矩阵项和子矩阵项,并尝试通过更改子记录的 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}

【问题讨论】:

    标签: netsuite suitescript


    【解决方案1】:

    根据错误消息(和您上面的代码),您正在尝试制作具有相同矩阵组合的子矩阵项,即所有具有 ma​​trixoptioncustitem44 值为 的子项2。 例如。就像 T-shirt 是你的父矩阵项,它的所有子矩阵项都具有相同的大小 M。 这是无效的,因为子矩阵应该有不同的大小(根据上面的例子)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 2017-09-14
      • 2017-04-08
      • 2017-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多