If you have an existing dataset with filters and y...
# suitescript
m
If you have an existing dataset with filters and you load it with
query.load
. Is it possible to add an additional filter to the existing ones in a script? Basically the dataset won't include the record id that I want to search, but a lot of other filters necessary that I want to be able to tweak more easily than in code. But I want the script to just add the record id when it loads and runs the query.
d
Yes. The query.load returns a Query object where you can use the
Query.createCondition(options)
to add additional conditions/criteria/filters (whatever you want to call them)
m
Usually how you enter filters is something like this:
Copy code
const test_query = query.create({
  type: query.Type.TRANSACTION
});

test_query.condition = test_query.and(
  test_query.createCondition({
    fieldId: 'id',
    operator: query.Operator.ANY_OF, 
    values: [record_id]
  })
);
Are you saying that if I do this it will work and not zero out the existing conditions and just add the new one?
Copy code
const test_query = query.create({
  id: 'dataset_id'
});

test_query.condition = test_query.and(
  test_query.createCondition({
    fieldId: 'id',
    operator: query.Operator.ANY_OF, 
    values: [record_id]
  })
);
d
something like this
Copy code
require(['N','N/ui/dialog'], function(N,dialog) {
for(var n in N){window[n] = N[n];};
try{

var myLoadedQuery = query.load({
    id: 'custdataset13'
});
console.log(myLoadedQuery);
console.log(myLoadedQuery.run().asMappedResults());

    myLoadedQuery.condition = myLoadedQuery.and(
        myLoadedQuery.condition, myLoadedQuery.createCondition({
            fieldId: 'assigned',
            operator: query.Operator.EQUAL,
            values: 3959
        })
    );
    console.log(myLoadedQuery.run().asMappedResults());
    
    } catch(e){console.error(e.message);}})
m
That makes sense. I see you added in the existing ones as a parameter.