Restrict the close of the catalog task in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2023 09:58 AM
Hi All,
I need to restrict the closing of the catalog task from the user.
Negative scenarios
1. If the user is not part of the catalog task assignment group, they can't able to close the task
2. If the user is "requested for" then he can't able to close the task.
Positive scenarios
1. If the person who raised the request he can close the catalog task
2. If the person belong to the particular assignment group then he can close the catalog task.
3. If the person belong to the "Authorize-ITSM" group then he can close the catalog task.
I have written the onload client script
g_form.setReadOnly('state', false);
else{
g_form.setReadOnly('state', true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2023 11:02 AM
Based on your description, you want to restrict the closing of the catalog task based on certain conditions. To achieve this, you can modify your existing script to include the additional condition of checking if the user is a member of the "Authorize-ITSM" group. Here's an updated version of the script:
OnLoad Client Script:
function onLoad() {
var groupId = g_form.getValue('assignment_group');
var req = g_form.getValue('u_requested_by');
var get = new GlideAjax('CheckUserMember');
get.addParam('sysparm_name', 'checkUser');
get.addParam('sysparm_group', groupId);
get.addParam('sysparm_req', g_user.userID);
get.getXML(addOpts);
function addOpts(resp) {
var answer = resp.responseXML.documentElement.getAttribute('answer');
if (
(g_user.hasRole('itil') && answer === 'true') ||
g_user.hasRole('admin') ||
req === g_user.userID ||
g_user.isMemberOf('Authorize-ITSM')
) {
g_form.setReadOnly('state', false);
} else {
g_form.setReadOnly('state', true);
}
}
}
Script include
var CheckUserMember = Class.create();
CheckUserMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkUser: function() {
var isMember = 'false';
var group = this.getParameter('sysparm_group');
var requestor = this.getParameter('sysparm_req');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group.sys_id', group);
gr.addQuery('user.sys_id', requestor);
gr.query();
if (gr.next()) {
isMember = 'true';
}
return isMember;
},
type: 'CheckUserMember'
});
In this updated script, the condition g_user.isMemberOf('Authorize-ITSM') is added to check if the current user is a member of the "Authorize-ITSM" group. This condition is included in the if statement to determine if the user can close the catalog task.
Please ensure that the sys_id provided for the "Authorize-ITSM" group is correct and matches the group's ID in your instance. Additionally, ensure that the Script Include is correctly referenced in the onLoad Client Script and that the Script Include itself is correctly named.
After implementing these changes, the catalog task closure should be restricted based on the specified conditions.
Please mark my answer as a solution/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal.
Thanks,
Punit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 12:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 03:06 AM
Hi All,
The below script is working fine, except one condition like "ITIL" user can edit the task state.
I have written the onload client script
g_form.setReadOnly('state', false);
else{
g_form.setReadOnly('state', true);
}
}