If I want to get a single value from a record with...
# suitescript
m
If I want to get a single value from a record without loading it, what's the best way? Doing a search?
s
imo it depends in your situation if you are looking up one record and one field, but you have the ID it'll be search.lookupFields if you are looking up one record and multiple fields but you have the ID and you're sure the type it's probably search.lookupFields if you are looking up multiple records and multiple fields it'll be a search.create/load -> run -> getRange/.each if you are looking at multiple records unsure of the record type it'll be a search.create/load -> run -> getRange/.each (looking at you NS item master) Added benefit is seach.lookupFields also queries custom lists I think
...quietly waiting to see if the overlords recommend the query module hypno parrot dark
m
@Sciuridae54696d, Saved your post, so helpful... thank you!
keanu thanks 2
s
You're too kind, so extra pointers success kid If you need to datajoin, as in via field to get a field within that record, it's automatically gonna be a search.create/load -> run -> getRange/.each scenario. Another rule is before a search, think about the datajoins, you're allowed to do a one level data join in N/search, more often than not there is one place that'll fulfill all the criteria... And use that to your advantage to save a lot of units. Also learn to manipulate and build javascript objects, do big searches get what you need, build that in an object, then use that object to do what you want. This helped me save a lot of units, so instead of per say journal line, trying to do a few searches per line, learn to loop through all the lines, get all the criteria, do a massive search, then reapply per line on the journal. hope it helps!
🙏🏼 1
s
FYI, NFT has a pre-built, elegant, unit tested and flexible 'build an object' called nsSearchResult2Obj you're welcome to use. https://github.com/ExploreConsulting/netsuite-fasttrack-toolkit-ss2/blob/32994a7f6fb151c19cc0936b45ad39569b572cb9/search.ts#L53
s
If you need to datajoin, as in via field to get a field within that record, it's automatically gonna be a search.create/load -> run -> getRange/.each scenario.
That is not 100% accurate... you can access joined data with search.lookupFields as well.
👀 1
m
Thank you all for your input. I'm asking because I'm trying to learn the right way on my way to my certification process.
s
I don't have a lot of respect for the NetSuite Certifications around development.
s
@Sandii didn't realise o-o
m
@stalbert why is that? It seems to me that it opens up a lot of employment positions.
s
it may, especially for folks without a lot of experience otherwise. I just don't think being certified means you're a good suitescript developer. I kept my certification active for a few years but have since stopped bothering. I may do it again sometime but don't feel it made me a better suitescripter.
In other words, NS certification would not be a factor in my hiring someone because I don't feel it carries much meaning, but I'm a technical person making that evaluation. Recruiters or others may assume otherwise. Also, I know it used to be important for NS partners (maybe it still is?) that they have a certain number of certified people as it increases their standing with NS.