Hello everyone :slightly_smiling_face: So, we have...
# suitescript
m
Hello everyone 🙂 So, we have a M/R that needs to run after a Sales Order is saved. We’re triggering it in an afterSubmit in a UE script (and passing in data to the M/R). About 80% of the time, it’ fine, but it too often throws the
Record Has Changed
error. There are a lot of UEs using AfterSubmit and WFs also using AfterSubmit in this account, so I am guessing that’s the issue. Is there a good workaround for this? Triggering the M/R a different way? a Different type of script? Any help is appreciated.
e
In the short term, you could potentially implement a retry mechanism into your M/R. Identify the
save()
call(s) throwing the error, and when you catch a
RECORD_HAS_CHANGED
error, retry your
set*()
and
save()
again. In the long-term, it might be worth a dedicated effort to consolidate the various customizations so that the record is being submitted as few times as possible and only multiple times when it actually needs to be.
💯 1
m
Yea, maybe that’s a good short term plan, thanks for the idea
m
I wrote this library to make retry logic concise and consistent. You would use it like this:
Copy code
function updateSalesOrder(orderId) {

	// load and save your SO here

}

retry({
	functionToExecute: updateSalesOrder,
	arguments: [123],
	maxTries: 3,
	retryOnError: 'RECORD_HAS_CHANGED'
});
❤️ 1
In this example, it would retry on 'RECORD_HAS_CHANGED' but fail as expected on any other error.
m
@Mike Robbins @erictgrubaugh thanks for the suggestions here and sorry for another ping, but trying re-saves didn’t work consistently enough. This account is pretty muddied up with UE scripts and WorkFlows using the AfterSubmit, and there are not the resources to consolidate them right now. We could handle the task a different way, so that we aren’t triggering a M/R with a UE, but I’d need access to the
netamount
formula numeric field that is available via saved search, and would need that data in a beforeSubmit of a UE script. As I understand it, that isn’t available in a UE and/or not the beforeSubmit entry point, as it calculates any/all discounts, etc. on an item for that particular Sales Order. Do you know if that’s an accurate assessment? Do you know of any way to get that numeric formula value in a beforeSubmit? Thank you very much!