- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 04:30 AM
Hi everyone
Please see if you can see what is wrong with my code. I created a business rule that should hide the 'high priority' option on the incident form for all users except those in the BST-Service Desk group. It does not seem to work? Only Service Desk should be able to raise the priority to P1 (High).
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 08:39 AM - edited 07-16-2024 09:46 AM
Hi @Thereza Van der,
Thanks for confirming. As an FYI and something you should be mindful of is the Priority lookup Rules. It's here where the Priority is calculated from a matrix of Urgency and Impact values.
To view these, type and select: Priority lookup Rules in the In the Navigation menu.
If group membership were not an issue, you could simply update the Lookup rule that when Urgency and Impact are '1 - High', the Priority could be set to '2 - High' (Rather than the Out Of Box default of '1 - Critical').
No code would be needed, however, group membership is in context so we will need to use a Script Include and Client Script with a slight tweak to what was provided before.
Rather than remove the option of Priority 1, as this is a read only and a calculated value, let's remove the impact value of 1 which essentially means based on the Priority Lookup Rules, if Impact of 1 can not be selected, then the Priority can never be 1 (Assuming the Lookup rules have not been changed)
Client Script:
function onLoad() {
var priorityField = 'impact'; // Change this to 'impact' if you want to test on another field which should be editable (OOB config)
var groupName = 'BST-Service Desk'; // Rather than hardcoding, can we use a form field such as Assignment Group to make this dynamic?
var sysid = g_user.userID; //get current user sysid
var userGroupGA = new GlideAjax('global.CheckUserGroup'); //script include name
userGroupGA.addParam('sysparm_name', 'getgroup'); //function name
userGroupGA.addParam('sysparm_name_sysid', sysid); //passing sysid to server
userGroupGA.addParam('sysparm_name_groupName', groupName); //passing group name to server
userGroupGA.getXMLAnswer(getGroup);
function getGroup(response) {
if (response == 'true') {
g_form.addInfoMessage('Part of group');
//g_form.addOption(priorityField, '1', '1 - High'); // You don't need to add this as it's part of the default list, you only need to remove it in the else
} else {
g_form.addInfoMessage('Not Part of group');
g_form.removeOption(priorityField, '1');
}
}
}
Script Include: (The same as before, but just in case)
var CheckUserGroup = Class.create();
CheckUserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getgroup: function() {
var usersysid = this.getParameter('sysparm_name_sysid');//getting usersy sid from client
var groupName = this.getParameter('sysparm_name_groupName');//get group from client (Dynamic and should be used)
var mem = new GlideRecord("sys_user_grmember");
mem.addQuery('user', usersysid); //filtering current user
mem.addQuery('group.name', groupName);
mem.query();
if (mem.next()) {
return true;
} else {
return false;
}
},
type: 'CheckuserGroup'
});
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 05:50 AM - edited 07-16-2024 09:07 AM
Hi @Thereza Van der,
Appreciate some days in the life of a SN dev/admin can be challenging.
It seems you have a mix of Server side code and Client side code in your example and simply put - it wont work.
Here's the solution. You need to call a Script Include (Server Side code) from a Client Script (Client Side).
Use the below which is tried and tested. Please note however, Priority is normally a calculated field driven by Impact and Urgency.
Do you/your org not calculate this, it's a select-able and editable field?
Client Script:
function onLoad() {
var priorityField = 'priority'; // Change this to 'impact' if you want to test on another field which should be editable (OOB config)
var groupName = 'ACME Support'; // Rather than hardcoding, can we use a form field such as Assignment Group to make this dynamic?
var sysid = g_user.userID; //get current user sysid
var userGroupGA = new GlideAjax('global.CheckUserGroup'); //script include name
userGroupGA.addParam('sysparm_name', 'getgroup'); //function name
userGroupGA.addParam('sysparm_name_sysid', sysid); //passing sysid to server
userGroupGA.addParam('sysparm_name_groupName', groupName); //passing group name to server
userGroupGA.getXMLAnswer(getGroup);
function getGroup(response) {
if (response == 'true') {
g_form.addInfoMessage('Part of group');
//g_form.addOption(priorityField, '1', '1 - High'); // You don't need to add this as it's part of the default list, you only need to remove it in the else
} else {
g_form.addInfoMessage('Not Part of group');
g_form.removeOption(priorityField, '1');
}
}
}
Script Include:
var CheckUserGroup = Class.create();
CheckUserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getgroup: function() {
var usersysid = this.getParameter('sysparm_name_sysid');//getting usersy sid from client
var groupName = this.getParameter('sysparm_name_groupName');//get group from client (Dynamic and should be used)
var mem = new GlideRecord("sys_user_grmember");
mem.addQuery('user', usersysid); //filtering current user
mem.addQuery('group.name', groupName);
mem.query();
if (mem.next()) {
return true;
} else {
return false;
}
},
type: 'CheckuserGroup'
});
Screen shot:
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 08:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 06:23 AM
Hi Robbie 🙂
Regarding your comment below you are correct, priority is a calculated field driven by Impact and Urgency.
Please note however, Priority is normally a calculated field driven by Impact and Urgency.
Do you/your org not calculate this, it's a select-able and editable field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 08:39 AM - edited 07-16-2024 09:46 AM
Hi @Thereza Van der,
Thanks for confirming. As an FYI and something you should be mindful of is the Priority lookup Rules. It's here where the Priority is calculated from a matrix of Urgency and Impact values.
To view these, type and select: Priority lookup Rules in the In the Navigation menu.
If group membership were not an issue, you could simply update the Lookup rule that when Urgency and Impact are '1 - High', the Priority could be set to '2 - High' (Rather than the Out Of Box default of '1 - Critical').
No code would be needed, however, group membership is in context so we will need to use a Script Include and Client Script with a slight tweak to what was provided before.
Rather than remove the option of Priority 1, as this is a read only and a calculated value, let's remove the impact value of 1 which essentially means based on the Priority Lookup Rules, if Impact of 1 can not be selected, then the Priority can never be 1 (Assuming the Lookup rules have not been changed)
Client Script:
function onLoad() {
var priorityField = 'impact'; // Change this to 'impact' if you want to test on another field which should be editable (OOB config)
var groupName = 'BST-Service Desk'; // Rather than hardcoding, can we use a form field such as Assignment Group to make this dynamic?
var sysid = g_user.userID; //get current user sysid
var userGroupGA = new GlideAjax('global.CheckUserGroup'); //script include name
userGroupGA.addParam('sysparm_name', 'getgroup'); //function name
userGroupGA.addParam('sysparm_name_sysid', sysid); //passing sysid to server
userGroupGA.addParam('sysparm_name_groupName', groupName); //passing group name to server
userGroupGA.getXMLAnswer(getGroup);
function getGroup(response) {
if (response == 'true') {
g_form.addInfoMessage('Part of group');
//g_form.addOption(priorityField, '1', '1 - High'); // You don't need to add this as it's part of the default list, you only need to remove it in the else
} else {
g_form.addInfoMessage('Not Part of group');
g_form.removeOption(priorityField, '1');
}
}
}
Script Include: (The same as before, but just in case)
var CheckUserGroup = Class.create();
CheckUserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getgroup: function() {
var usersysid = this.getParameter('sysparm_name_sysid');//getting usersy sid from client
var groupName = this.getParameter('sysparm_name_groupName');//get group from client (Dynamic and should be used)
var mem = new GlideRecord("sys_user_grmember");
mem.addQuery('user', usersysid); //filtering current user
mem.addQuery('group.name', groupName);
mem.query();
if (mem.next()) {
return true;
} else {
return false;
}
},
type: 'CheckuserGroup'
});
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 09:28 AM
Thank you Robbie for going out of you way to assist me. REALLY appreciate it!