<@UHSPS2FNV> You need to analyze your script/scrip...
# suitescript
a
@Siena You need to analyze your script/scripts… generally: - If you can’t get what you need with a
search
or
lookupFields
. - If you can’t do what you need with
submitFields
. - If you can’t do what you need in
beforeSubmit
. - Then and only THEN you load the record…
s
I admit I do not agree wit this assertion.
a
@stalbert So you don’t like to load the record as your last resort?
s
correct. In general I feel a search is heavier and slower than a record load. So it depends on what you're doing - if I'm processing 1 million records and only need a couple fields, I'll use a search rather than loading a million records.
if that search would have to run for each of the million records, I'd definitely just load the record if possible (i.e. I have an internal id to do so)
s
is lookupFields slower than loading the records?
a
When doing a search I got the columns and data I wish, when loading a record I can’t control or know how many fields the record would have and how much data… could be 10 custom fields on top of the standards and could be 500 custom fields…
My point is you have more control over searches data than the records data…
m
@Siena Lookupfield is faster than loading a record and is based on search. The real answer is that search is faster (or close to the sames) for very specific data (record this type, id this number, for instance), but slower for everything else.
s
lookupFields
is a mini-search as far as I can tell. I agree with you @alien4u but I also don't know exactly how NS implements these different calls on the database. Maybe it's a restricted SELECT statement with searches and a * for columns with a record load, I dunno.
m
So really my suggestion would be the following:
1) Use nlapiLookupField and nlapiSubmitField first
2) Then use nlapiLoadRecord
3) Use nlapiLoadSearch when you are dealing with a lot of similar records or complex formula
s
have you measured that lookupField is faster than loading? I have assumed so but can't recall actually measuring it.
m
Most of the time I use them they are about the same
I haven't measured
Netsuite's documentation says it's faster, but it may just be lighter weight processing in any case
But yeah, @Siena, I'd save search for things you'd use the Searches in the UI for. Lots of data or Formulas.
(or things that can't be loaded easily, there's sometimes data that's easier to get via a search with System Notes, for instance). That's a rare situation of course.
s
I could use lookupFields for some of this but I have a function already built to extract an address out of a loaded sales order and idk how that would even work with just field names since I'm loading the address subrecord... so maybe I have to load it after all
m
if it has a subrecord, use nlapiLoadRecord
nlapiLookupField doesn't work with subrecords
So your fine
the performance hit for using nlapiLoadRecord is about the fastest you will get
Is it being done in a client script or a server side script (basically anything else?)
s
yea thats what I was afraid of. So I guess I have to load the record after all, but if I'm loading it in multiple scheduled scripts it will still run the risk of throwing the RCRD_HAS_BEEN_CHANGED error
its scheduled scripts, so serverside
m
So the scheduled scripts are running concurrently?
a
@Siena Any particular reason to load the same record multiple times in different scripts?
s
sometimes this can come up through no fault of your own - for example some SuiteApp installed that works with the same record type.
s
It depends how the client sets them up, but they may be. And they may be working on invoices and item fulfillments in separate scripts, that all are created from the same Sales Order. Its the sales order loading that has me concerned now
m
Hmmm... the only thought I have is to just delay opening that record and try opening it later
s
Basically I have separate scripts running for Invoices, Item Fulfillments, etc, and I need information off the sales order that they were created from. So I load the Sales Order
a
@Siena You should post here some uses cases, maybe somebody here see how to approach those uses cases in a different way.
m
does the error happen on load or on submit?
s
It seemed to happen on submit
a
@Siena Right there…
m
Okay. Are you iterating through a list of record, or just opening one specific record?
a
Those script using the created from(Sales Order) should not be loading the record again to get data, for that you do a search and your problem is solved.
m
@alien4u I think she's changing data on the sublist, so it wouldn't work =/.
a
@Siena And you only need a search if you are getting line level data, otherwise just lookupFields.
m
COuld be wrong though
a
What I’m understanding is needed data from the Sales Order and not modifying the Sales Order from the Invoice or Fulfillment.
m
Mmm... yeah, in that case, a search would work too
s
So what led me to believe that maybe it was the SO being loaded was the case where 2 item fulfillments were being processed in my script (ie. iterating through a list of the records) and I had already loaded the SO from the first iteration, and it didnt like me reloading. But I also thought my script would have caught that separately before it ever got to where it was failing. According to the error it failed in a separate catch statement at the end of my code, on itemfulfill.save(). So implying it was the item fulfillment throwing the error, not the sales order. Tbh I am not sure what the error was caused by.
I am not modifying the Sales Order in these scripts, however I do need address information off the sales order
Which is in the subrecords
a
@Siena Your problem would be solve switching those record loads to searches.
s
So I'm loading the SO so that I can use
Copy code
addr = so.getSubrecord({
                    fieldId: 'billingaddress'
                });
Ok I'll have to look into how to get the address information from the search. You mean a full search right, not lookupFields?
m
Yep, a full search
a
You may need a full search…
m
actually ideally, it's best to build it in the UI so you know what you want.
then you can load it to get the paramaters and build it via a script
s
Yea that's what I'll do and then the fancy chrome extension can tell me what the search should be in suitescript 🙂
a
@Siena You may be able to get away with lookupFields getting the addresstext which is at the Sales Order body level.
m
Yeah that works
yeah, what alien4u said, that would probably be the way
s
No because I need the fields individually for mapping purposes, and won't that just give me a string that I'd need to parse myself?
m
The other things you might look into is the 'Address Fields ...' join.
Your going to have to deal with that either way
Some addresses are entered in data using the 'Custom' checkbox
For those, there isn't any filled out fields
It might be best to grab those that have the 'state', 'city', etc, but also have an address parsing library to help
s
Hmm oh boy, I haven't run into that yet
m
At least that's what I'd do =/
But who knows
if nobody uses custom addresses are your work, you might not need to
Address parsing is hard =/
So let's hope you don't have to
s
Yea we might just be the mean bad guys who say no custom addresses allowed or something
I hope I dont have to haha
At least now I'm aware that this might come up
m
Yeah. No prob. Try what alien4u said for now and I hope it works out for ya 🙂
Man that big smiley emoticon looks so weird so I had to change it...
Anyways, @alien4u sorry about jumping all over this, you were handling it fine
👍 1
a
Help is always good…
👍 1
s
Thanks for all the help!
👍 1