```items.forEach(function (item) { log...
# suitescript
k
Copy code
items.forEach(function (item) {
            log.debug('Item Sku' , item.sku)
            search.create(
                {type:'item', filters: [['itemid', 'is', item.sku]]
               }).run().each(function(result){
                log.debug('Result ID: ', result.id)
              });

}
e
you have to return true
s
yeah its possible and it's also terribly inefficient
😂 1
k
What is a better approach for this?
I am Passing a whole order with all the Line_items which is an array that holds each item as an object
e
Agree it is inefficient. If it’s a small operation, it might be fine so depends on what you’re doing. If you’re doing thousands of iterations, it’s going to be very slow and you’ll likely run into governance limits.
But, the reason you’re only getting 1 result is that you’re not returning true from your each() function. If you don’t return true, it will stop after 1 iteration.
k
👍 what is a more efficient way of doing this task?
@eblackey thank you
Most likely an order will not have more than 20 skus
About few orders per mins
e
What type of script will this be on? UserEvent, ScheduledScript?
k
Its a restlet
I have a Nodejs that will call it and send data back and forth
Most likely not scheduled
e
You might consider if you could load up the item data you need in cache using the N/cache module. That way, you’re not hitting the DB on each call. If you need realtime data like qty on hand, that might not work.
s
you can pass an array into the search criteria, like
[item, 'anyof', idArray]
and do a single search and process the results
k
ahh
Ok I will look into these suggestions, thank you
z
@Ken You may be better off running a transaction search and then adding joins to the item fields you need in the search. So then you are returning the order as a search with the extra fields and not looping the lines and doing a lookup on each line. It is way faster. Or even turning that search into a sql query would be much faster.
d
Use the N/query to get the line data you need before the loop. Significantly faster than N/search. Also, the cache idea above is a great one if you're calling the same order several times within a few minutes.
a
So @dcrsmith when is the chrome extension for N/query module coming out? 😉 It cause of your extension that I have a hard time moving away from N/search
d
I released it before SW. Keep in mind it's BETA. One thing I've noticed and haven't fixed is that you have to refresh the page after selecting the workbook for the button to show up.
a
Oh. Nice! I was making a joke!
There was actually one previously released by someone else but for some reason it was removed from the chrome store
d
👍 This was very challenging to get SS2.0 into the extension. Hopefully it works ok...