- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 06:14 AM
Hi,
On our project we created a flow that when a users department is updated a flow runs and their assignment group updates accordingly to match the department name. To note: the assignment groups have the same name as the departments.
We created this flow so that when a users department is updated, the flow executes and the users assignment group updates accordingly to match the department name.
Due to provisioning the users after this flow, the flow did not execute. There is now a requirement on the project, to run a background script that adds the users to the correct assignment group based on the same department name.
I am new to servicenow and need guidance on creating and running this background script.
It would be much appreciated if i could be provided with some help, support and guidance.
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 06:25 AM
Hi @Daniel R2 ,
You can give a try to below script :-
First try this for only 1 record by applying encoded query, as it is not tested.
var grUser = new GlideRecord("sys_user");
grUser.query();
while (grUser.next()) {
var grGroup = new GlideRecord("sys_user_grmember");
grGroup.initialize();
var gr = new GlideRecord("sys_user_group");
gr.addQuery("name", grUser.getDisplayValue('department'));
gr.query();
if (gr.next()) {
grGroup.user = grUser.sys_id;
grGroup.group = gr.sys_id;
grGroup.insert();
}
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 06:25 AM
Hi @Daniel R2 ,
You can give a try to below script :-
First try this for only 1 record by applying encoded query, as it is not tested.
var grUser = new GlideRecord("sys_user");
grUser.query();
while (grUser.next()) {
var grGroup = new GlideRecord("sys_user_grmember");
grGroup.initialize();
var gr = new GlideRecord("sys_user_group");
gr.addQuery("name", grUser.getDisplayValue('department'));
gr.query();
if (gr.next()) {
grGroup.user = grUser.sys_id;
grGroup.group = gr.sys_id;
grGroup.insert();
}
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 07:09 AM
@Gunjan Kiratkar - Thank you for your help Gunjan! This is exactly what I required 😁
Thanks for also being available in private messages and taking the time to clarify further questions at a fast pace!
It is much appreciated