Hi all, running into an issue with one of our user...
# suitescript
x
Hi all, running into an issue with one of our user event (aftersubmit) scripts. Basically after submit of a custom record, the script is suppose to make some updates on the linked work order which can include changing the assembly item. We've noticed that when there is an assembly item change, the assembly item field changes as expected but the components in the line items are not re-calculating properly. The quantity on the work order could be 100 but the components change to as if it was quantity 1. record.load is dynamic mode. The only thing that kind of stands out to me is if I change the assembly item via the UI, I do get the warning "this item is back ordered" and I have to click OK, could that be causing issues when done via userevent? I broke the code down to it's basic function so that nothing else was interfering and I still get the above unexpected behavior. Screenshots of the WO and item setup also attached.
Copy code
/**  
 *@NApiVersion 2.0
 *@NScriptType UserEventScript
 */
define(['N/record', 'N/log'],
            function(record, log) {
           
                var Tester_Item = '23361';

                function woItemAfterSubmit(context) {
                    log.debug({
                        title: 'start',
                        details: context.type
                    });
                    if (context.type != context.UserEventType.EDIT) {

                        log.debug({
                            details: "Event is not Edit. Exiting."
                        });
                        return;
                    }
                    var currentRecord = context.newRecord;
                    var recId = currentRecord.id;
                    var woId = currentRecord.getValue({
                        fieldId: 'custrecord_work_order'
                    });

                    var recWorkOrder = record.load({
                        type: record.Type.WORK_ORDER,
                        id: woId,
                        isDynamic: true
                    });

                    recWorkOrder.setValue({
                        fieldId: 'assemblyitem',
                        value: Tester_Item
                    });

                    recWorkOrder.save({
                        enableSourcing: true,
                        ignoreMandatoryFields: true
                    }); //submit canning work orderrecord


                }
                return {
                    afterSubmit: woItemAfterSubmit,
                };
            });
b
set the quantity