How to check if current user in particular group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2024 10:11 PM
How to check if current user is in particular group if he is not in that group he will be added to that group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2024 10:29 PM
how to create record in sys_user_grmember
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2024 10:56 PM
Hi
Use this script to create a membership
var user = "SYS_id"; //User Sys_id
var member = new GlideRecord('sys_user_grmember');
member.initialize();
member.user = user;
member.group = 'SYS_ID'; //Group Sys_id
member.insert();
Mark my answer Helpful & Accepted if I have answered your question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2024 11:02 PM - edited ā01-31-2024 11:05 PM
Hi Akash,
You can use this script to create record.
var gr=new GlideRecord("sys_user_grmember");
gr.addQuery('group','sys_id'); //sys_id of the group.
gr.addQuery('user',gs.getUserID());
gr.query();
if(gr.next()){
return true;
//gs.log("true");
}
else{
gr.initialize();
gr.user=gs.getUserID();
gr.group='sys_id'; //sys_id of the group.
gr.insert();
}
Let me know if you are stuck.
Please mark it helpful if you feel this answered your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2024 11:27 PM
to create record in Group Member table you can use below script
var gr = new GlideRecord('sys_user_grmember');
gr.initialize();
gr.user = '<sys id of user>';
gr.group = '<sys id of group>';
gr.insert();
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-31-2024 10:46 PM
where are you checking it? the script will depend on that
what's your business requirement and what script did you start and where are you stuck?
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader