- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 06:46 PM
Hi
My requirement is to add one role to particular groups by using fix script.
There are some filter conditions while querying the group table , below are the filter conditions
Group should be active, group should be itil, and group should be non working group.
By using those conditions we need to get that particular groups if those conditions are matched then we need to check that particular groups has sn_role , if this role is there to that groups then dont do any thing , if that role is not there to that groups then add sn_role.
This is my requirement.
Please suggest with your answers.
Thanks in advance
Regards
Aarya
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 07:51 PM
Hi,
something like this; enhance it
addRole();
function addRole(){
try{
var gr = new GlideRecord("sys_user_group");
gr.addEncodedQuery("Your Query"); // give your query here
gr.query();
while(gr.next()) {
var gr1 = new GlideRecord("sys_group_has_role");
gr1.addQuery("group", gr.getUniqueValue());
gr1.addQuery("role.name", "sn_role"); // give exact role name here
gr1.query();
if (!gr1.hasNext()) {
gr1.initialize();
gr1.group = gr.getUniqueValue();
gr1.setDisplayValue('role','sn_role'); // give exact role name here
gr1.insert();
}
}
}
catch(ex){
gs.info(ex);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 07:03 PM
Hi,
So what script did you start and where are you stuck?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 07:11 PM
Hi
I need to write a fix script in that first i need to query the group table to match the conditions and to get that particular groups if it is done and next step should check that groups has "sn_role" or not.
if that groups has that role then no need to do any thing,
If that groups doesnt have that role then need to add "sn_role"
And sorry i didnt start the script , i know the logic but dont know how to write a script as iam new to servicenow.
Please help me
Regards
Aarya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 07:34 PM
If you start on your own it would be learning for you as well.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 07:37 PM
Hi
Today i need to show to my team, i dont have time now.
Please help me
Regards
Aarya