I may be dumb on this ! still I want to know ? Why...
# suitescript
t
I may be dumb on this ! still I want to know ? Why its happening ? > Bottle1 replaced by alpha1 > and length of filter is 3 at first filter log
b
you pushed the same array into the filters twice
👍 1
and made a modification to it
l
When you modify the source object it will change on array too because it's same object... you need to clone it to modify just one
t
I was expecting [["itemid", "is", "Bottle1"], "OR",["itemid", "is", "alpha2"]] as last filter log
b
you pushed in the same array object twice
the first element and the second of the element of filter is the same object: array
l
try change the second "push(array);" to "push(JSON.parse(JSON.stringify(array)));"
it will create a new object
In some languages when you add an object into an array it create a copy of this object into this array but in JS it still linked to source object so any changes on source will affect the objects inside the array
👍 1
t
But I replaced the
b
@Luiz Morais solution will push in a new array, but you still modified the first one, so your log will show the changes you made to the first one
im not sure what you are trying to do, but you shouldnt be trying to reuse arrays as filters
make a new one for each search filter you want to represent
l
I guess he wants to add multiple item ids as filter
t
yes
b
Copy code
var filter = [["itemid", "is", "Bottle1"], "OR", ["itemid", "is", "alpha2"]];
l
I don't think you need to create a template array before push... you could just push new array with item id like: push(["itemid","is", anyVariable]);
b
if you wanted something that is more obvious to use in a loop, use:
Copy code
var filter = [['itemid', 'is', 'Bottle1']]
filter.push('OR', ['itemid', 'is', 'alpha2'])
👍 1
keep in mind that a formula using the IN condition might also work
beware, for item searches, itemid refers to all the names of the item, including vendor name and display name
use nameinternal for only the itemid
t
Okay , I'll keep this in mind. Thanks !