how to hide the "closed" dropdown of state field in incident table, only for a specific group member
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 06:03 AM
I want not to hide the "closed" dropdown of state field in incident table, only for a specific group member, and need to hide for all the other members ,
I have written the script as below , i am not gating out put please correct this.
Please let me know if any alternate solution for this.
Script include:
var CheckGroupMembership = Class.create();
CheckGroupMembership.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isUserMemberOfITIL: function() {
var user = gs.getUser();
return user.isMemberOf('Team Development Code Reviewers').toString();
}
});
Client script:
function onLoad() {
var closedOption = g_form.getOption('state', '7'); // '7' represents the 'Closed' state, replace it with the actual value for your instance
g_form.addInfoMessage('1');
// Use GlideAjax to call a server-side script that checks the user's group membership
var ga = new GlideAjax('CheckGroupMembership');
g_form.addInfoMessage('2');
ga.addParam('sysparm_name', 'isUserMemberOfITIL');
g_form.addInfoMessage('3');
ga.getXMLAnswer(function(response) {
g_form.addInfoMessage('4');
console.log("GlideAjax response: " + response);
// Parse the response as JSON, as GlideAjax might return a structured response
var parsedResponse = JSON.parse(response);
if (parsedResponse.result === 'true') {
// If the user is a member of ITIL, show the "Closed" option
g_form.setOption('state', closedOption, true);
} else {
// If the user is not a member of ITIL, hide the "Closed" option
g_form.removeOption('state', '7');
}
});
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 06:14 AM
update as this
Client script
function onLoad() {
// Use GlideAjax to call a server-side script that checks the user's group membership
var ga = new GlideAjax('CheckGroupMembership');
ga.addParam('sysparm_name', 'isUserMemberOfITIL');
ga.getXMLAnswer(function(answer) {
if (answer == 'false') {
g_form.removeOption('state', '7');
}
});
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader