Hi everyone, i ran into this odd scenario for a Re...
# suitescript
h
Hi everyone, i ran into this odd scenario for a Restlet to create/update a Sales Order. The code has always been working for subsidiary in the US. However, when the Sales Order's customer subsidiary is Canada or Mexico, it just would not set the four fields in the Else statement at all. Has anyone came acrossed this before?
Copy code
if (salesOrderId) {
		log.debug({ title: 'Load existing sales order', details: salesOrderId });

					salesOrder = record.load({
						type: record.Type.SALES_ORDER,
						id: salesOrderId,
						isDynamic: true
					});
				}
else {
		log.debug('Create a new Sales Order');
		salesOrder = record.create({
			type: record.Type.SALES_ORDER,
			isDynamic: true
		});
					  salesOrder.setValue('custbody_al_load_number', externalId);
salesOrder.setValue('tranid', externalId);
salesOrder.setValue('externalid', 'LO' + externalId);
salesOrder.setValue('custbody_al_accelerate_id', externalId);
					
}
c
The else statement includes the record.create() call and the field setValues call - how are those fields' values ever set when the sales order exists already via
salesOrderId
?
a
when setting field values in the dynamic mode the order of operations matter a lot
setting subsidiary and entity will unset a lot of data that you might have already set, so its best to just set those first
1
do it like you'd do it the UI
(I'm assuming you're conditionally setting subsidiary at some point AFTER this in the script)
simplest fix is probably to just set a variable in place of those 4 setValues isCreate = true; and then later on in your script use that isCreate to conditionally set those 4 values after setting subsid etc.
h
I've never set subsidiary on the Sales order since i thought it would flow through from the Customer record. Let me try your approach of setting the subsidiary first
a
oh if you're NOT setting it later in the script then you're right, it should be pre-populated
i did say that was an assumption i was making
h
Thanks @Anthony OConnor that was the culprit. After I set those fields AFTER setting the customer, it works now 🙂
👍 1
@Clay Roper if the SO already exists, i don't set those fields anymore