IN operator

endoflineone
Kilo Explorer

Has anyone seen how to emulate the IN operator of a SQL where clause with addQuery() method?

For example gr.addQuery('sys_id','IN','val1,val2,val3...');

IN or IS ONE OF and NOT ONE OF are not explained here http://wiki.service-now.com/index.php?title=Querying_a_Service-now_Table_from_Javascript#Available_JavaScript_Operators


I can create URL using IN (IS ONE OF in filter) using this construct sysparm_query=sys_idIN0331ddb40a0a3c0e40c83e9f7520f860%2C032ebb5a0a0a3c0e2e2204a495526dce, but would like to use addQuery() in a Script for UI page , Business Rule, or Scheduled Job.

3 REPLIES 3

Jay_Ford
Kilo Guru

I think you just need to use...



gr.addQuery('sys_idIN0331ddb40a0a3c0e40c83e9f7520f860,032ebb5a0a0a3c0e2e2204a495526dce,...');


Yes it does. Thanks a million. I also found that this works too.
ci.addQuery('sys_id','IN','0331ddb40a0a3c0e40c83e9f7520f860,032ebb5a0a0a3c0e2e2204a495526dce');

They key to this is not to attempt to build an array object to hold the test values or enclose inside () like a SQL construct. e.g. "('0331ddb40a0a3c0e40c83e9f7520f860','032ebb5a0a0a3c0e2e2204a495526dce',...)" does not work for the 3rd param.


john_roberts
Mega Guru

It doesn't help in the URL, but FYI, you can also pass an array variable as the 3rd parameter.