Skip to content

Commit ea1c649

Browse files
Merge branch 'main' into SCIM-Payload-Generator
2 parents a3cd3e1 + d0c077e commit ea1c649

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var rec = new GlideRecord('sys_user_group');
2+
rec.addEncodedQuery(''); //get the list of groups needed.
3+
rec.query();
4+
while (rec.next())
5+
{
6+
var rec1 = new GlideRecord('sys_user_grmember');
7+
rec1.addQuery('group' , rec.sys_id);
8+
rec1.addQuery('user' , '7279f455939e71944c77b6b5fbba1033'); // put the sys_id of "user" here
9+
rec1.query();
10+
if(!rec1.next()) //checking if group member is already existed. if not, we add them.
11+
{
12+
rec1.initialize();
13+
rec1.group = rec.sys_id;
14+
rec1.user = '7279f455939e71944c77b6b5fbba1033'; // put the sys_id of "user 1" here, to insert group member
15+
rec1.insert();
16+
gs.log("User group record inserted");
17+
}
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
**Script to Add a User to list of User Groups Where They Are Not Already a Member**
2+
3+
Purpose: we often recive requests add a single group member to multiple groups. that's a manual task. this script makes it very simple.
4+
5+
- **The first GlideRecord('sys_user_group')**: Creates a GlideRecord instance to query the `sys_user_group` table.
6+
7+
- **addEncodedQuery('')**: Add the required list of groups here, by copying filter from list of groups.
8+
9+
- We use while loop to loop through list of groups.
10+
11+
- **The second GlideRecord('sys_user_grmember')**: For each group, creates a new GlideRecord instance to query the `sys_user_grmember` table (user-group memberships).
12+
13+
- **addQuery('group', rec.sys_id)**: Filters the `sys_user_grmember` records by the current group’s `sys_id`.
14+
15+
- **addQuery('user', '7279f455939e71944c77b6b5fbba1033')**: Filters the records for the specific user's `sys_id` ( this is sample sys id. replace with the actual `sys_id` of the user).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function onLoad() {
2+
//Type appropriate comment here, and begin script below
3+
if (g_form.getValue('priority') == '1') {
4+
g_form.setLabelOf('description', 'Please Explain Briefly');
5+
}
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
# Change Label of Field
3+
4+
• Modify field labels dynamically in the ServiceNow platform.
5+
6+
• Change labels through the UI form designer or through client/server-side scripts.
7+
8+
• Implement Business Rules to change labels based on conditions.
9+
10+
• Adjust field labels dynamically using Client Scripts based on user interactions.
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var slaAgg = new GlideAggregate('task_sla');
2+
slaAgg.addQuery('task.active', true); // Only active tasks
3+
slaAgg.groupBy('task.assignment_group'); // Group by assignment group
4+
slaAgg.addAggregate('COUNT'); // Count the number of active SLAs per assignment group
5+
slaAgg.query();
6+
7+
while (slaAgg.next()) {
8+
var assignmentGroup = slaAgg.getValue('task.assignment_group.name');
9+
var slaCount = slaAgg.getAggregate('COUNT');
10+
gs.info('Assignment Group: ' + assignmentGroup + ' has ' + slaCount + ' active SLAs.');
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SLA Count by Assignment Group
2+
3+
This script retrieves active SLAs (task_sla table) grouped by assignment groups in ServiceNow. It counts the number of active SLAs per group and logs the result, displaying the group name and corresponding SLA count.

0 commit comments

Comments
 (0)