The CreatorCon Call for Content is officially open! Get started here.

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

Rajat_Choudhary
Tera Expert

Hi @LRhodes ,

 

Please use this code.

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

Thanks,

Please mark the answer correct and helpful. If solution is feasible.

 

Hope this answers will be helpful.
Please mark the answer as helpful and correct.

Best Regards,
Rajat Choudhary

Thanks Rajat, this seems to be hiding the field okay when the result is false. However when it's true it also still seems to be hiding it so I'm not sure if it's reading the value correctly.

Also slight oversight on my side the variable is caller_id.u_daas_user

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); 
		
	}
}

Great to hear that @LRhodes .

Always Happy to help. 

Hope this answers will be helpful.
Please mark the answer as helpful and correct.

Best Regards,
Rajat Choudhary