0
votes

I am trying to create an inventory adjustment from a MAP/REDUCE script. the record from which i am setting the values is getting ftom a search in getInputData(). In map function i am loading that custom record and setting these values

var newcase_inv_Adj = record.create({type:'inventoryadjustment',isDynamic:true});

            newcase_inv_Adj.setValue({fieldId:'account',value:creel_account});
            newcase_inv_Adj.setValue({fieldId:'custbody_cp_adjreasoncode',value:creel_reasoncode});
            newcase_inv_Adj.setValue({fieldId: 'custbody_c_from', value: name});

            newcase_inv_Adj.selectNewLine({sublistId:'inventory'});     
    newcase_inv_Adj.setCurrentSublistValue({sublistId:'inventory',fieldId:'item',value:creel_item});
            newcase_inv_Adj.setCurrentSublistValue({sublistId:'inventory',fieldId:'location',value:creellocation});
            newcase_inv_Adj.setCurrentSublistValue({sublistId:'inventory',fieldId:'adjustqtyby',value:creel_weigh_oh});
            var create_inv_detail = newcase_inv_Adj.getCurrentSublistSubrecord({sublistId: 'inventory',fieldId: 'inventorydetail'});
            create_inv_detail.selectNewLine({sublistId:'inventoryassignment' });
            create_inv_detail.setCurrentSublistValue({sublistId:'inventoryassignment',fieldId:'receiptinventorynumber',value: creel_casenumber});
            create_inv_detail.setCurrentSublistText({sublistId:'inventoryassignment',fieldId:'binnumber',value: creel_bin });
            create_inv_detail.setCurrentSublistValue({sublistId:'inventoryassignment',fieldId:'quantity',value: creel_weigh_oh });
            create_inv_detail.commitLine('inventoryassignment');log.debug("N","commited  inventoryassignment");
            newcase_inv_Adj.commitLine({sublistId:'inventory'});log.debug("N","commited  inventory");
            var invAdjID = newcase_inv_Adj.save();log.debug("N","invAdjID : "+invAdjID);

But, I am getting this error as {"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR" Is it because of Map/Reduce script?

1

1 Answers

0
votes

I don't find anything wrong in the code.

Few suggestions: - Follow the sequence: Set subsidiary value before you setvalue for account or any other mandatory field. - First try with inventory items without serial numbers and see if you continue to face same problem. - You need to make sure you all your variables has valid value (not null or undefined). - First try doing this in a schedule script.