From a Sales ORder client script, after someone se...
# suitescript
r
From a Sales ORder client script, after someone selects a customer, I need to get the zip code of that customer, then pass that onto another function. In terms of efficiency, would it be better to do a
N/record.load()
on the customer ID when it's selected, or create a simple saved search with one result column of the zip code, then run that saved search with the customer ID as the filter? I know a
N/record.load()
is resource intensive because it will trigger other things, but creaing a saved search just for a single value off a customer record seems superflous
e
There is also
search.lookupFields
that doesn't load the customer I wonder if after selecting the customer... is not an address field in the SO that gets populated after sourcing the customer?
e
Depends on which Zip you need. Customers can have a bunch of addresses
👍 1
m
A few things to note. (1)
search.lookupFields()
is a good option as @Edgar Valdes says. It uses
N/search
in the background, which is slightly less intensive than
N/record
. Of course, loading the record isn't that much slower either - so I wouldn't worry about this enormously. (2) As @erictgrubaugh said, customers can have many addresses - shipping, billing, and then there's the ones in the address list. I'm not sure
search.lookupFields()
will work on the ones in the address list that are not the shipping and billing address. (3) You also need to prepare for the scenario of there not being a zip. Addresses can be entered in a freeform 'Custom' way, if a user selects that specific check mark that's on the right side of the address record. If they do that, they sometimes leave the zip field blank. You'll need to train your users or use a script to force them to not do this (and you can use a search to lookup and see if any addresses are currently in this state).
👍 1
e
I prefer
search.lookupFields()
over
record.load()
for simple field retrieval because sometimes, somewhere, a record can be locked by a workflow. This lock prevent the load, but not the lookup (or the search/query if thats the case). The SO has
billzip
and
shipzip
, but not sure when are those fields available for the scripts (after customer sourcing, after address re-select, before submit, after submit, etc)
r
@Edgar Valdes that was my concern, that a full
.load()
would trigger unecessary workflows. I will experiment with the
.lookupFields()
and getting zip from primary shipping address (yes, I have code for missing values)
r
Idk why you don't want to use suiteql / search. I always prefer them over lookup field. Record Load should be a big no. There is also an option of cache module btw. You can do a function in your script if cache doesn't exist it recreates it or if cache doesn't have a zip for a customer it recreates it. If you lot of sales order gets created in UI. Caching can also be one route you could go towards. Although I don't prefer it but I have seen a lot of similar use cases for it.
r
I don't not want to use search, thats why I was asking what the better way was since, as confirmed, using
N/record.load()
to get the data I was looking for was bad practice.
b
fair chance that the zip is already on the sales order
once you select the customer, the addresses are sourced onto the sales order
r
I know default shipping address is auto-copied over. So, process flow question would be, should I do any error catching or collision catching on if my client script runs to get the Sales Order shipping zip code (that would have been auto filled by native code selecting the customer) for some reason runs before the native code that would have set that value?
b
use the postSourcing entry point
👍 1