Is there a way to tell if we in a `beforeSubmit` o...
# suitescript
m
Is there a way to tell if we in a
beforeSubmit
or
afterSubmit
? We have a shared library that's used in both scenarios and we need to take a different approach depending on before or after. Thanks!
r
Create a dictionary in your library. With 2 keys beforeSubmit and afterSubmit. Pass whatever you want to do as value in each. Call the respective key in beforeSubmit and afterSubmit of your userevent ?
m
Thanks! That's a great idea and worked exactly as I hoped.
s
I would have taken a slightly different approach - factored the common logic into your library and give it a reasonable name (i.e. not beforeSubmit or afterSubmit) then put the unique code for beforeSubmit or afterSubmit on the actual UE script as appropriate.
r
if it's hard coding of some data (like field internal Ids or something else, I will keep it in library files. if the logic is some functions/conditions, I will move the logic to userEvent as well. Dictionary keys name were just to make it more understandable, name it something that might make more sense.
m
The story here is we're modifying the Avalara scripts to reduce the number of unnecessary API calls. For example, if nothing in the Avalara API request body has changed, then don't send the API call since we’ve already calculated tax with that data. We're storing a hash of the API request in a custom field so we can tell when the request body has changed. The challenge is that sometimes Avalara calls that API in beforeSubmit (Estimate, SO, RA) and sometime it’s called in afterSubmit (Invoice, Cash Sales). To keep our footprint small in their code, our logic is in a custom library. In beforeSubmit, we can set the hash by referencing the current record. In afterSubmit, we need to use submitFields. I just needed to know which was which.