Add existing users to group through script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 02:18 PM
I want to add existing users to group and create a business rule to check if the user exist in the group if not add to the group
Please can someone help with script
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 05:56 PM
Can we use glide aggregate script to assign the existing users to group? can you share if you write one?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 06:17 PM
Why use GlideAggregate to add 1 record?
GlideAggregate is use to query database table using aggregation such as using AVG, COUNT, MIN, MAX, STDDEV, SUM. It's not used to add record.
https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server_legacy/c_GlideAggregateAPI

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 07:26 PM
GlideAggregate is like SELECT... GROUP BY in sql. It's used to retrieve records but it's not possible to insert nor update records.
To assign user to a group in ServiceNow, it's necessary to insert a record into sys_user_grmember table. Since this is an insert operation, GlideAggregate can not be used. That is, GlideAggregate does not have .insert() nor .update() methods like GlideRecord.
If it's necessary to update multiple users at the same time. .updateMultiple() method in GlideRecord can be used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2022 04:32 AM
I want to assign a role to the users who are in system_owner field in CMDB_CI table, So I thought i will add the existing users to a group and add a role to group, and when new record are created if the System_owner field has user assigned then we check for existing if not we will add new users to the group.
I thought adding existing users to group we might need glide aggregate, I might be wrong.
Please can you provide necessary script to achieve this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2022 08:14 AM
Its Owned_by field