Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Display field on Incident only if value is true.

LRhodes
Tera Guru

Hi - on our incident records we pull through a custom field from the sys_user table, specifically from the record of the user in the caller_id field.

find_real_file.png

What I want to achieve is that this 'DaaS User' field will only show if the value of the true|false is true. If it returns false then it should not show on the Incident record.

I have tried the following client script which runs OnLoad;

function onLoad() {
   
	if(u_daas_user == true){		
		g_form.setDisplay("u_daas_user", true); 
	}	
	else {		
		g_form.setDisplay("u_daas_user", false);		
	}
	
}

Unfortunately this doesn't seem to be doing the trick. Any ideas what I may be doing wrong?

1 ACCEPTED SOLUTION

I've managed to get it working. Looks like there's an issue with ServiceNow client scripts returning Boolean variables. Followed the below to tweak it a little and it works. Thanks for your help!

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783585

 

function onLoad() {
	
	var daas_user = g_form.getValue("caller_id.u_daas_user");
	
	if(daas_user == 'true'){ 
		
		g_form.setDisplay("caller_id.u_daas_user", true); 
		
	} 
	
	else { 
		
		g_form.setDisplay("caller_id.u_daas_user", false); 
		
	}
}

View solution in original post

6 REPLIES 6

Hitoshi Ozawa
Giga Sage
Giga Sage

Or

g_form.setDisplay("u_daas_user", g_form.getValue("u_daas_user"));

Hitoshi Ozawa
Giga Sage
Giga Sage

The code doesn't seem to make too much sense. The script is trying to show/hide by the value of itself.