Visible the field based on custom table

deepika adimu
Tera Contributor

Need to display field based on custom flag which is created in user table. I tried ACL it working, is there anyway to hide the field based on flag

1 ACCEPTED SOLUTION

Mohan raj
Mega Sage

Hi @deepika adimu,

Using Glide Record in Client script is not best practice, Try to use client callable script include to display the field

 

Script Include :

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

checkFlag: function(){
		var sysID = this.getParameter('sysparm_uniqueNum');
		var user = new GlideRecord('sys_user');
		user.addQuery('sys_id',sysID);
		user.query();
		if(user.next()){
			return user.u_custom_field;
		}
	},

    type: 'TestingScript '
});


 and call this script include in On Load Client script to hide the field based on the flag

 

function onLoad() {
    var ga = new GlideAjax('TestingScript ');
	ga.addParam('sysparm_name','checkFlag');
	ga.addParam('sysparm_uniqueNum',g_user.userID);
	ga.getXML(callBack);
	function callBack(response){
		var answer = response.responseXML.documentElement.getAttribute('answer');
		alert(answer);
		if(answer == 'false'){
			g_form.setDisplay('u_field',false);
		}else{
			g_form.setDisplay('u_field',true);
		}
	}
}

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Regards,

T Mohan.

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@deepika adimu 

can you explain field is on which table and how this table is linked/related with user table?

please share screenshots.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Mohan raj
Mega Sage

Hi @deepika adimu,

Using Glide Record in Client script is not best practice, Try to use client callable script include to display the field

 

Script Include :

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

checkFlag: function(){
		var sysID = this.getParameter('sysparm_uniqueNum');
		var user = new GlideRecord('sys_user');
		user.addQuery('sys_id',sysID);
		user.query();
		if(user.next()){
			return user.u_custom_field;
		}
	},

    type: 'TestingScript '
});


 and call this script include in On Load Client script to hide the field based on the flag

 

function onLoad() {
    var ga = new GlideAjax('TestingScript ');
	ga.addParam('sysparm_name','checkFlag');
	ga.addParam('sysparm_uniqueNum',g_user.userID);
	ga.getXML(callBack);
	function callBack(response){
		var answer = response.responseXML.documentElement.getAttribute('answer');
		alert(answer);
		if(answer == 'false'){
			g_form.setDisplay('u_field',false);
		}else{
			g_form.setDisplay('u_field',true);
		}
	}
}

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Regards,

T Mohan.