Hi Everyone. I'm stumped and hoping someone can p...
# suitescript
m
Hi Everyone. I'm stumped and hoping someone can point me in the right direction. I have a userEvent script running on afterSubmit on Work Order transactions. I am trying to change the Bill of Materials field ('billofmaterials') if the customer has a specific configuration. I am successfully setting this field and the Revision and Routing is cascading down correctly. However, the line items are not changing like they do in the UI. Here is my setValue call: wo.setValue({fieldId: 'billofmaterials', value: customerProductBOM, ignoreFieldChange: false, forceSyncSourcing: true}) I am loading the Work Order in Dynamic mode and then saving the record. Any thoughts that might help here?
s
Try doing it in beforeSubmit instead?
m
So these are being created from the Sales Order as Special Work Order Items. Unless I'm mistaken, I can't get access in beforeSubmit when the Work Orders are created this way.
b
try manually setting the revision and routing
m
same behavior, unfortunately.
The one thing I wonder about is, in the UI, when I change the BOM, I get a qty notification that certain items have a 0 quantity. Could that prompt be stopping the cascade?
b
its a sandbox, you can do an inventory adjustment to find out
m
yea, the items the prompt is mentioning are all 'phantoms' in the BOM, though and set to Do Not Commit. Strange behavior.
b
what does the code look like
m
Copy code
//Check to see if there is a Customer Product BOM based on the Parent of the Customer on the Work Order.  If so, use that BOM configuration.
                if(customer){
                    let customerParent = search.lookupFields({type: search.Type.CUSTOMER, id: customer, columns: ['parent' ]}).parent[0].value;
                    let customerProductSearch = search.create({
                        type: "customrecord_customer_products",
                        filters:
                        [
                        ["custrecord_customer_products_customer.internalid","anyof",customerParent],
                        ],
                        columns:
                        [
                        search.createColumn({name: "internalid", join: "CUSTRECORD_CUSTOMER_PRODUCTS_CUST_ITEM", label: "Item Internal ID"}),
                        search.createColumn({name: "custrecord_customer_products_cust_item", label: "Customer Item"}),
                        search.createColumn({name: "custrecord_cust_product_bom", label: "Customer BOM"})
                        ]
                    });
        
                    customerProductSearch.run().each(function(result){
                        let item = result.getValue({name: "internalid", join: "CUSTRECORD_CUSTOMER_PRODUCTS_CUST_ITEM", label: "Item Internal ID"})
                        if(item == assembly){
                                let customerProductBOM = result.getValue({name: "custrecord_cust_product_bom", label: "Customer BOM"});
                                if(customerProductBOM){


                                    wo.setValue({fieldId: 'billofmaterials', value: customerProductBOM, ignoreFieldChange: false});
                                    wo.setValue({fieldId: 'billofmaterialsrevision', value: 108091, ignoreFieldChange: false});
                                    wo.setValue({fieldId: 'manufacturingrouting', value: 734, ignoreFieldChange: false});

                                    log.debug('BoM Found', `BoM found for ${item}`);
                                    log.debug('BOM', result.getValue({name: "custrecord_cust_product_bom", label: "Customer BOM"}));
                                    
                                    return;
                                }
                                
                        }
                        return true;
                    });
                };
I've tried setting it outside of the loop as well. same thing