How to return a list of group sys_ids

margie_joyce
Kilo Contributor

Hello,

I want to write a function which returns a list of groups I can use in a filter, for example:

Assignment group is javascript:myGroupList()

So, it is like the getMyGroups() function in that it needs to return a list of groups.

However, while I can assemble the groups I need, I'm not sure how to return it.

I've tried putting them into an array of group sys_ids. I've tried returning a string in the format
[group_sys_id, group_sys_id, group_sys_id]
... but neither of these gives me the result I need.

My question is, how do I return a "list" of group sys_ids from a function which can be used in a filter?

thanks
margie

4 REPLIES 4

CapaJC
ServiceNow Employee
ServiceNow Employee

Check the getMyAssignments() function in the getMyApprovals business rule. It returns an array of sys_user sys_ids that can be used in a filter like:
assigned_to is javascript:getMyAssignments()

Maybe it can point you in the right direction? I know getMyGroups() used to be in a business rule but was moved into the Java at some point, else you could use that as a guide instead.

Sorry and please disregard if you've already gone this route.


Thanks!

The bit I was missing was creating the string object as I pushed the item into the array.

So I've replaced:

groups.push(gr.sys_id);

with:

groups.push(new String(gr.sys_id));

and it works fine.

Many, many thanks.

margie


You could also use gr.sys_id.toString()
Here's some information on javascript variables being passed as value versus by reference. Converting the sys_id to a string forces the value to be passed as a value, breaking the link from the referenced object.


Thanks - I appreciate your input, and it does help me understand what's going on.

margie