Catalog item variable need to be in read only when particular user impersonate

praveen1231
Tera Contributor
Hi, My requitement is to create a catalog Item variable called Manager(sys_user) and Committe(sys_user). When I impersonate the user with Title CEO or user with Title CIO, both the variable manager and committee should turned as ReadOnly. If you have any idea, please let me know Thank you.
1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @praveen1231 ,

 

Try the following onLoad Catalog client script and a Client Callable Script Include.

 

Catalog Client Script:

 

function onLoad() {
    var ga = new GlideAjax('UserDataUtils');
    ga.addParam("sysparm_name", "getTitle");
    ga.addParam("sysparm_user_id", g_user.userID);
    ga.getXMLAnswer(validateUser);

    function validateUser(answer) {
        if (answer.indexOf('CIO') != -1 || answer.indexOf('CEO') != -1) {
            g_form.setReadOnly('your_field_name', true);// Change field name as per your requirement
        }
    }

}

 

AnveshKumarM_0-1695717894876.png

 

Client Callable Script Include:

var UserDataUtils = Class.create();
UserDataUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getTitle: function(){
		var user_id = this.getParameter('sysparm_user_id');
		var usrGr = new GlideRecord('sys_user');
		if(usrGr.get(user_id)){
			return usrGr.getValue('title') + '';
		}
	},

    type: 'UserDataUtils'
});

 

AnveshKumarM_1-1695717913510.png

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

 

 

Thanks,
Anvesh

View solution in original post

4 REPLIES 4

Omkar Kumbhar
Mega Sage
Mega Sage

Hello @praveen1231 ,

you can create an onload catalog client script. use the g_form.getUserID() which you give you the current logged in user and dot walk check the title in if loop.

later user g_form.setReadOnly('varaible_name',true);

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

use g_user.getUserID()  there is also another way calling the script inlcude in client script using glideajax

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

 Can you please share me the entire code of client script. And need to check the user with title.

AnveshKumar M
Tera Sage
Tera Sage

Hi @praveen1231 ,

 

Try the following onLoad Catalog client script and a Client Callable Script Include.

 

Catalog Client Script:

 

function onLoad() {
    var ga = new GlideAjax('UserDataUtils');
    ga.addParam("sysparm_name", "getTitle");
    ga.addParam("sysparm_user_id", g_user.userID);
    ga.getXMLAnswer(validateUser);

    function validateUser(answer) {
        if (answer.indexOf('CIO') != -1 || answer.indexOf('CEO') != -1) {
            g_form.setReadOnly('your_field_name', true);// Change field name as per your requirement
        }
    }

}

 

AnveshKumarM_0-1695717894876.png

 

Client Callable Script Include:

var UserDataUtils = Class.create();
UserDataUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getTitle: function(){
		var user_id = this.getParameter('sysparm_user_id');
		var usrGr = new GlideRecord('sys_user');
		if(usrGr.get(user_id)){
			return usrGr.getValue('title') + '';
		}
	},

    type: 'UserDataUtils'
});

 

AnveshKumarM_1-1695717913510.png

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

 

 

Thanks,
Anvesh