I'm trying to get all the values of a custom list ...
# suitescript
m
I'm trying to get all the values of a custom list and I've found suite answers id: 63265, but when I try to run scripts in a test environment this morning I keep getting an error saying that 'require is not defined', can someone help me figure out what's going on?
b
on a different note, that is a bad javascript
the array should be an object
m
I was kinda thinking the same thing, I thought shouldn't it be { id: result.id, value: result.getValue(searchColumn) } or something similar
and that object could be pushed to the array that way I'm not wasting iterations on looping passed nulls
b
as in
Copy code
var listArray = {};
keys are ids and values are names
m
oh so, taking the array portion out entirely and storing objects in the parent object
b
Arrays are objects, the code works the same way
m
fair enough
b
its just that arrays are objects with a special length
and tend to be printed differently
you would use an object over an array for the same reason you wouldnt use
Copy code
var listArray = new Date();
m
mainly for code readability then? so that someone doesn't think they know what the type is based on the name only to get it wrong
b
the name of the variable doesnt really matter
its that you arent using any of the Date related funcionality
or in the code they shared, any array functionality
m
so if I were to use array related functionality like .indexOf I should leave it as an array then?
b
usually you chose your key wrong if you are trying to index it by value
m
hmm well I'm in a scenario where I have values coming from a third party source so I know the value but when I'm matching that up to the list in NetSuite I need to find the correct id from this list. That's why I'm using this method to load the list and then find the id. Is there a better way to do it?
b
usually you treat arrays as lists of values, not as a map of key value pairs
performance wise, using an array means finding a value means going through every value until you find the matching one
m
thanks for taking time to help me out man, I feel like I have a ton to learn from pros like you
b
meh, this is not really suitescript or even javascript related, its more computer science
in this particular case, choosing the best data structure for your needs
for your question, reversing how the object is keyed allows a more constant time lookup vs linear performance lookup
m
I appreciate it, I should really do more work on understanding those data structures so that I cause less system stress and write better performing code
b
Copy code
listArray[searchResult.getValue(searchColumn)] = searchResult.id;
m
oh so instead of returning the index like with indexOf I would simply be able to ref the value because I already have what would now be the key
b
its what i mentioned about choosing the keys and values wrong
m
that's simple and really straightforward
If I don't find my value, what is the easiest way to write the value to the custom list?
b
Easiest is probably treating the custom list as a custom record and creating a new custom record
Correct is probably treating is as a custom list and loading the custom list record and modifying the values sublist
m
yeah I don't want to create more NEW custom lists, I just want to keep the same custom list correctly up to date. I just wasn't sure how I needed to go about doing that. I'll see if I can load the custom list record by script id and then update the values sub-list
401 Views