- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 08:44 PM
Hi,
When monitoring team & delivery team members are creating security incident then source should be "phone" by default. it should restrict others to create a source is phone.
EX:
I'm member of monitoring team and I'm creating security incident after click on new button then source should be phone for me and for others it should be none.
Regards,
Sanju
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:37 PM
it's showing error, even the part of that particular group and after that I added myself as user from that particular group. then it's working fine but for the existed users it's not working. I'm I created function in right way? why it's showing error like this.
EXISTING USERS:
FOR ME:
CLIENT SCRIPT:
function onLoad() {
var sysid = g_user.userID; //get current user sysid
var ga = new GlideAjax('sn_si.CheckUserGroup'); //script include name
ga.addParam('sysparm_name', 'getgroup'); //function name
ga.addParam('sysparm_name_sysid', sysid); //passing sysid to server
ga.getXMLAnswer(getGroup);
function getGroup(response) {
if (response == 'true') {
g_form.addInfoMessage('Part of group');
g_form.setValue('contact_type','dlp');
g_form.setReadOnly('contact_type',true); // If you want to restrict the field from changing value
} else {
g_form.addInfoMessage(response);
g_form.addInfoMessage('Not Part of group');
g_form.setValue('contact_type', '');//Keep blank
g_form.setReadOnly('contact_type',true); // If you want to restrict the field from changing value
}
}
}
SCRIPT INCLUDE:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:42 PM
Hi @Talari Balateja ,
Script is taking the login user. Please try after impersonating the user who is present in that group.
Impersonating an user will solve your issue.
Thanks!
Abhishek Dalvi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 09:23 PM
Update code, also pls apply some log:
(function executeRule(current, previous /*null when async*/) {
// Check if the current user is a member of monitoring or delivery team
var currentUser = gs.getUser();
var monitoringTeam = gs.getUser().isMemberOf('Phone Monitoring Team');
var deliveryTeam = gs.getUser().isMemberOf('Secure Delivery Team');
if (monitoringTeam || deliveryTeam) {
// Set source to "phone"
current.contact_type = 'phone';
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 09:30 PM
tried but it's not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 09:35 PM
Check Group or Role Names: Ensure that the group or role names 'Phone Monitoring Team' and 'Secure Delivery Team' are correct and exist in your ServiceNow instance. Even a small difference in names can cause the script not to work.
Debugging: Lets inspect where code is getting failed
(function executeRule(current, previous /*null when async*/) {
// Check if the current user is a member of monitoring or delivery team
var currentUser = gs.getUser();
gs.info("Current User: " + currentUser.getName()); // Log current user
var monitoringTeam = currentUser.isMemberOf('Phone Monitoring Team');
gs.info("Is in monitoring team: " + monitoringTeam); // Log monitoring team membership
var deliveryTeam = currentUser.isMemberOf('Secure Delivery Team');
gs.info("Is in delivery team: " + deliveryTeam); // Log delivery team membership
if (monitoringTeam || deliveryTeam) {
// Set source to "phone"
gs.info("GroupMemberLog "+"InsideIf");
current.contact_type = 'phone';
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 10:57 PM - edited 04-02-2024 10:58 PM
Hi @Talari Balateja ,
You can go with the below mentioned solution.
1. Create a client script (onLoad) and paste the below code -
function onLoad() {
var sysid = g_user.userID; //get current user sysid
var ga = new GlideAjax('global.CheckUserGroup'); //script include name
ga.addParam('sysparm_name', 'getgroup'); //function name
ga.addParam('sysparm_name_sysid', sysid); //passing sysid to server
ga.getXMLAnswer(getGroup);
function getGroup(response) {
if (response == 'true') {
g_form.addInfoMessage('Part of group');
g_form.setValue('field_name','choice_name');
g_form.setReadOnly('field_name',true); // If you want to restrict the field from changing value
} else {
g_form.addInfoMessage(response);
g_form.addInfoMessage('Not Part of group');
g_form.setValue('field_name', '');//Keep blank
g_form.setReadOnly('field_name',true); // If you want to restrict the field from changing value
}
}
}
2. Create Script Include with below code and name -
Script include name - CheckUserGroup
function name - getgroup
Accessible from - All Application scope
Client callable - true
Code -
var CheckUserGroup = Class.create();
CheckUserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getgroup: function() {
var usersysid = this.getParameter('sysparm_name_sysid');//getting usersysid from client
var mem = new GlideRecord("sys_user_grmember");
mem.addEncodedQuery('user='+ usersysid+'^group=aaccc971c0a8001500fe1ff4302de101^ORgroup=019ad92ec7230010393d265c95c260dd'); // Replace your group sys id in this query
mem.query();
if (mem.next()) {
return true;
} else {
return false;
}
},
type: 'CheckUserGroup'
});
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me.
Thank you!
Abhishek Dalvi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 11:39 PM
I got this error:
Client script
function onLoad() {
var sysid = g_user.userID; //get current user sysid
var ga = new GlideAjax('sn_si.CheckUserGroup'); //script include name
ga.addParam('sysparm_name', 'getgroup'); //function name
ga.addParam('sysparm_name_sysid', sysid); //passing sysid to server
ga.getXMLAnswer(getGroup);
function getGroup(response) {
if (response == 'true') {
g_form.addInfoMessage('Part of group');
g_form.setValue('contact_type','DLP');
g_form.setReadOnly('contact_type',true); // If you want to restrict the field from changing value
} else {
g_form.addInfoMessage(response);
g_form.addInfoMessage('Not Part of group');
g_form.setValue('contact_type', '');//Keep blank
g_form.setReadOnly('contact_type',true); // If you want to restrict the field from changing value
}
}
}
Script include: