Hi, looking for confirmation/suggestions for a pro...
# suitescript
g
Hi, looking for confirmation/suggestions for a project. I built a client script for my company, that when saving an order will validate the address against a API and return the corrections/validity in a popup and the user has to allow/not allow etc the changes.. Now they want a script that will run on orders and automatically fix them upon creation for all orders All shared functions I should move to a module that I would include in both of my scripts? What type of script should the new one be? It need to run on all orders upon creation, have edit access to the shipping address and be able to edit custom body fields on the sale
e
If I were you, I'd push back against this request. To trust an API to correct addresses without a human being able to say "Yes" or "No" to those changes sounds like a bad idea to me. We use a similar address validator API, and it's notorious for wanting to remove information that is necessary to get the shipment to the correct place. i.e. Many times things like "Apt 2" or "Suite G" etc will be removed when the address validator wants to "correct" the address.
Since you have a client script in place to do this already... does this mean you want to validate/correct addresses on Orders that come in from non-UI entry? Like importing of web orders or something similar?
g
yes
the only suggestions we are auto fixing is zip and city spelling mistake. other items will be marked accordingly and a scheduled search will send them to a user to fix
right now in the client script the fixes are offered and their is a lot of interaction with the user
@ericbirdsall what script options do i have for non-UI orders?
e
Fair enough. I'd recommend a beforeSubmit script.
g
that is of type userevent? it will run even if there was no user interaction
?
e
Correct. The beforeSubmit event fires just before the record (Order) is saved to the database
This will work for weborders that are brought in via suitelet/restlet/etc
g
ok thanks so much
👍 1
and if the functions are going to be the same as my client script, I should create a module t o share them?
(for maintenance purposes)
e
You could move your API logic to a module, but I'm not sure it's 100% necessary. I'd personally write this as a separate script and copy/paste the API bit from your client script. Once you've tested the new script and are sure it's working correctly, then you could see if your API logic/code is exactly the same, then you could create a module and reference it from both scripts
Since you're going from a client script to a server side script, you may need to make changes to your API logic (can't say without seeing it)
g
ok, thanks!