What does' sys_idIN' mean when used in a query? Eg : 'active=true^sys_idIN' + function( )

Rama Chandra D
Kilo Guru

I'm trying to figure out a script which has the syntax mentioned in the question, that is 'active=true^sys_idIN' + function( ). Can someone explain to me what does sys_idIN do here? Does it simply include the sys_id passes to the query as one of the a condition?

1 ACCEPTED SOLUTION

Use this



javascript: 'typeLIKExxxx^active=true^sys_idIN' + gs.getUser().getUserByID(user id).getMyGroups().toArray().join() + '^EQ'


View solution in original post

20 REPLIES 20

scottcornthwait
Kilo Expert

That encoded query would be populating a list of sys_id's that should be part of the query.



So if you needed to return all records where the sys_id is for example: 1, OR 2, OR 3, OR 4 ... and so on, it will return all the records where the sys_id matches. In the case you showed above, the function would be used to return that list, and append them into the query so that the encoded query would be dynamic based on the results of the function.


Rama Chandra D
Kilo Guru

So if i'm passing a list of groups through the 'function()' , my encoded query will essentially result in all those groups from the list which are active, is it? Or am I wrong?



Thanks,


Darshak


scottcornthwait
Kilo Expert

That's right,


So long as teh function returns a string value of sys_ids that are separated by , characters, then it would indeed return all records where teh sys_ids are in the group provided by the function.



This link actually has an example of exactly this. But rather than passing a function, it shows how the function would build the comma separated list of sys_ids to go into that encoded query.


http://wiki.servicenow.com/index.php?title=Reference_Qualifiers#JavaScript_Example:_Limiting_the_Ass...


Thank you so much. I have already been through the link you have mentioned however in my case, the encoded query i'm using is failing to list all the groups that have a particular user. Rather it is only showing up groups which has the user but with no 'roles'.



my encoded query is 'typeLIKExxxx^active=true^sys_idIN' + gs.getUser().getUserByID(user id).getMyGroups() + '^EQ';       xxxx is the sys_id for 'request' type .