- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 09:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 09:55 AM - edited 03-22-2023 10:04 AM
Hi @Joshua Comeau ,
Please create the Script include as per below image. While saving it will ask for roles make sure you give the role that the user has (eg. lTIL) then only the script will be executed.
Script
var CheckMemberOfGroup = Class.create();
CheckMemberOfGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
iSMemberOfGroup : function(){
var getGroupName = gs.getParameter('sysparm_groupName');
var result = gs.getUser().isMemberOf(getGroupName);
return result;
},
type: 'CheckMemberOfGroup'
});
now in the UI Policy / Client scripts use the below script as shown in image (if there is no condition to be checked i prefer to use OnLoad Client Script)
Script:
var checkMember = new GlideAjax("CheckMemberOfGroup");
checkMember.addParam('sysparm_name', "iSMemberOfGroup");
checkMember.addParam('sysparm_groupName', "Analysts"); //give the correct Group Name Here
checkMember.getXMLAnswer(callbackFunction);
function callbackFunction(answer) {
if (answer) {
g_form.setVariablesReadOnly(false);
}
}
Mark Helpful and accept the solution if it helps in Solving your query.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 09:55 AM - edited 03-22-2023 10:04 AM
Hi @Joshua Comeau ,
Please create the Script include as per below image. While saving it will ask for roles make sure you give the role that the user has (eg. lTIL) then only the script will be executed.
Script
var CheckMemberOfGroup = Class.create();
CheckMemberOfGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
iSMemberOfGroup : function(){
var getGroupName = gs.getParameter('sysparm_groupName');
var result = gs.getUser().isMemberOf(getGroupName);
return result;
},
type: 'CheckMemberOfGroup'
});
now in the UI Policy / Client scripts use the below script as shown in image (if there is no condition to be checked i prefer to use OnLoad Client Script)
Script:
var checkMember = new GlideAjax("CheckMemberOfGroup");
checkMember.addParam('sysparm_name', "iSMemberOfGroup");
checkMember.addParam('sysparm_groupName', "Analysts"); //give the correct Group Name Here
checkMember.getXMLAnswer(callbackFunction);
function callbackFunction(answer) {
if (answer) {
g_form.setVariablesReadOnly(false);
}
}
Mark Helpful and accept the solution if it helps in Solving your query.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 09:57 AM - edited 03-22-2023 10:01 AM
@Johns Marokky so their is two places I need to create and add these scripts in 1 in the ui policy and 1 in the client scripts?
I am not sure on where the first picture is located can you provide a further steps on how you went there or a more opened picture screenshot?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 10:03 AM
No.
The first script should be in the Script include.
the second script should be in Client Script as an OnLoad Client Script.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 10:06 AM
How to get to script include?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 10:10 AM
Type Script Include in the navigator or use the below link.
https://<instance_name>.service-now.com/sys_script_client.do