Is there a way to get the record into JSON format ...
# suitescript
n
Is there a way to get the record into JSON format via suitescript? In my script I'm doing a lot of getValues and I think it would be much easier if I can parse the JSON instead.
b
the probably safe but undocumented way is using .toJSON() on the record
n
hmm so in a Scheduled Script or user even load the record and then just add .toJson() on it?
b
n
awww okay i get what you mean! thanks I'll give it a shot!
s
You could build your own function as well if toJSON() is giving you problems... something like
_let_ recordValues = ['fieldid1', 'fieldid2', 'fieldid3'].reduce((_obj_, _val_) _=>_ { _obj_[_val_] = rec.getValue(_val_); return _obj_; }, {});
where
var rec = record.load()
s
You might want to take a look at NFT (NetSuite Fasttrack Toolkit) since it provides the ability to work with records as regular objects
👏🏻 1
n
@Sandii Oh I like that! Thanks for the help!
@scottvonduhn I've never heard of it but I'm going to definitely research that, sounds like a really helpful tool!
a
@ngill4492 Please consider that companies needs and/or implementations change and evolve with time, if one year from now your record has 200 custom fields (I seen that before) then your script is unnecessarily dumping your entire record with all the fields and values into memory when your real need is only 20 fields. On top of that toJSON() as @battk mentioned before is undocumented which mean NetSuite could remove or change that anytime and your whole script will break.
n
@alien4u That's a great point, I've also worked at companies with a lot of custom fields in the past. I was moreso curious on what others have done in that situation I do think maybe just creating a function to do the logic might be the option right now
Appreciate all the help!!