How do we check if value that is being populated to script include from UI Action has not value?

Sushma Uday C
Tera Contributor

Hello, 

We have a UI Action where we are getting caller from Work order and sending that to Script include.

Where we want to glide the value through user table and get Contact and email values.

So the tricky part is we were able to achieve it when we have value filled in caller field but when Caller field empty we are getting value as undefined.

So how do we filter the when we have empty caller field and replace it empty value in the place of undefined.

PFB screenshot of UI Actions and Script include for your reference.

And we are working this in scoped applications.

find_real_file.png

Script Include: I have gs.nil, Jsutil.notnil both didnt work 

var CareARforFSMWorkspace = Class.create();
CareARforFSMWorkspace.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
setDetails: function() {

var my_sysID = this.getParameter('sysparm_sysID');
var my_table = this.getParameter('sysparm_table');
var my_contact_sysID = this.getParameter('sysparm_contact_sysID');
gs.info("Value from UI Action" +my_contact_sysID);
var baseURL = gs.getProperty('x_care3_carear_fsm.web.base.url');
var fqdn = gs.getProperty('instance_name') + '.service-now.com';
var currentUser = gs.getUser();
var userName = currentUser.getDisplayName();
var gr = new GlideRecord(my_table);
if (!gr.isValid()) {
return;
}
gr.get(my_sysID);
if (!gr.canRead()) {
return;
}
var numberWO = gr.getDisplayValue('number');
var contactNo;
var contactEmail;
if(JSUtil.notNil(my_contact_sysID)){
var gr1 = new GlideRecord('sys_user');
gr1.addQuery('sys_id', my_contact_sysID);
gs.info("contactsysID" + my_contact_sysID);
gr1.query();
if (gr1.next()) {
contactNo = gr1.getValue('mobile_phone');
contactEmail = gr1.getValue('email');
} else{
contactNo = "";
contactEmail = "";
}
}

//build answer (URL)
var careARURL = baseURL + '?serviceNow=true&id=' + numberWO + '&name=' + userName + '&table_name=' + my_table + '&table_sys_id=' + my_sysID + '&contact=' + contactNo + '&email=' + contactEmail + '&fqdn=' + fqdn + '&origin=https://' + fqdn + '/now/workspace/agent/record/' + my_table + '/' + my_sysID + '&file_name=true';
return careARURL;
},

 

Thanks in Advance 🙂

1 REPLY 1

Jan Cernocky
Tera Guru

Hi Sushma,

I tried it on my own and the behavior is really odd.

What however works well, although not completely ideal is:

In client script add something like this

	if(g_form.getValue('caller_id')) {		
		ar.addParam('sysparm_contact_sysID', g_form.getValue('caller_id'));		
		
	}
	else {		
		ar.addParam('sysparm_contact_sysID', 'empty');		
	}

and in the script include do a simple check

		if(my_contact_sysID != 'empty') {
			return 'Value from UI Action is NOT null' + my_contact_sysID;			
		}
		else {
			return 'Value from UI Action is NULL';							
		}