UI Policy if a user is part of a group make variables editable

Joshua Comeau
Kilo Sage

I have the following and does not work any ideas on the reason?

JoshuaComeau_0-1679500848408.png

JoshuaComeau_1-1679500906660.png

 

 

1 ACCEPTED SOLUTION

Johns Marokky
Tera Guru

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.

Screenshot 2023-03-22 at 10.17.59 PM.png

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)

Screenshot 2023-03-22 at 10.34.02 PM.png

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

 

View solution in original post

10 REPLIES 10

Prince Arora
Tera Sage
Tera Sage

@Joshua Comeau ,

 

"gs" is the server side library, it will not work in client script.

For checking the same please find the link here 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Could you assist on writing the code 

so based on this link I would use: ga?

Johns Marokky
Tera Guru

Hi @Joshua Comeau ,

gs won't work in UI Side. its an Server side scripts.

What you can do is you can create an script include which checks the user is part of particular member or not and use the GlideAjax to call the script include in the client script.

 

Let me know if you need help with building the scripts for this.

 

Mark helpful if it helps in solving your query.

Regards,

Johns

 

100% please help with building this script :)!