1
votes

I have a small question. Generally in netsuite if we create a parent matrix item and along with that if i create six child matrix items,and if we update matrixoptions of any child matrix item the change is get reflected in the parent matrix item also The same i was tring to do through scripting but i was facing problems here is my code please help me

/**
 * @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
};

});

I had created the parent and chil matrix items and trying to update the child matrix item by changing the matrixitemoptions of child record but i was getting error like this:

{"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}
1

1 Answers

0
votes

As per the error message(and your above code), you are trying to make sub-matrix items with the same matrix-combination i.e all the child items that have matrixoptioncustitem44 value of 2. eg. Like T-shirt is your parent matrix item and all its sub-matrix items have the same size M. This is not valid, as sub-matrix should have different sizes (as per the above example).