Glide Record is always empty

bigbacon
Giga Guru

I am trying to get a script to go look up a record and grab a value to return during an onChange event.

 

I have this include:

var HRTT4UTicket = Class.create();
HRTT4UTicket.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getJobTitleCodeHRIS: function() {
		var sysid = this.getParameter('sysparm_sysid');

		try {
			var ghjobGR = new GlideRecord('sn_hr_core_greenhouse_job_import');
			ghjobGR.addQuery('sys_id', sysid);
			ghjobGR.query();
			
			if(ghjobGR.next()) {
				//var objReturn = {
				//	jobcodeHRIS : ghjobGR.JobCodeHRIS.toString()
				//};
				//return JSON.stringify(objReturn);
				return ghjobGR.JobCodeHRIS;
			}
			else {
				return 'nothing';
			}	
		}
		catch(e) {
			return 'error' + e;
		}		
	},
    type: 'HRTT4UTicket'
});

 

and what seems to be happening is even though I am sending a valid sys_id to this function, it just returns an empty record set for the given table, which causes it to always send a null value back.

 

I cannot figure out why this doesn't work. The sys_id being sent is valid, I can go to the table data list manually and look up the record but it will not do it through this client script. We have other similar scripts that seem to work just fine. 

 

I have also tried it as just a .get(sys_id) and that return the same result. 

 

It is like the script doesn't have access to the table yet it does?

 

I can make the script just return any random string and it gets returned just fine.

 

What am I missing here? 

21 REPLIES 21

Omkar Mone
Mega Sage

Can you also put your client script here?

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }   

   try {
       //alert(newValue);
        var ga = new GlideAjax('sn_hr_core.HRTT4UTicket');
        ga.addParam('sysparm_name', 'getJobTitleCodeHRIS');
        ga.addParam('sysparm_sysid', newValue);
        ga.getXML(doJobTitleCallback);
    } catch (err) {
        alert('error is ' + err);
    }

    function doJobTitleCallback(response) {
		//alert(response.responseXML.documentElement);
        var answer = response.responseXML.documentElement.getAttribute("answer");
		//alert(answer);
        //answer = JSON.parse(answer); //Transform the JSON string to an object
        g_form.setValue('u_job_code_title', answer);
        
   }

   //Type appropriate comment here, and begin script below
   //alert(newValue + ' ' + control);
}

This is not the problem though, again, even though this sends a valid sys_id to look up in the "sn_hr_core_greenhouse_job_import" table, it always returns nothing, as if that item doesn't exist in the table but it definitely does.

Can you try to run that block of code with the same sysid and see if it is returning any value? Please put the screenshots from the background script. Alternatively, also check for any ACL's if they are blocking.

paragkanoje
Tera Contributor

You just need to use below statement before return:

var returnValue = ghjobGR.JobCodeHRIS.getDisplayValue();
return returnValue;

Mark help full if it works.

 

Brad Bowman
Kilo Patron
Kilo Patron

The FIRST thing I always do when getting unexpected results is log, log, log.  Temporarily adding something like this will confirm this Script Include is running, the value passed in from the client, the user it is running as, and the record retrieved by the GlideRecord.  This should help you see what is going wrong in your specific instance.

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

    getJobTitleCodeHRIS: function() {
        var sysid = this.getParameter('sysparm_sysid');
        gs.info('HR SI running with import table sys_id = ' + sysid + ' running as user ' + gs.getUserName());

        try {
            var ghjobGR = new GlideRecord('sn_hr_core_greenhouse_job_import');
            ghjobGR.addQuery('sys_id', sysid);
            ghjobGR.query();
            if (ghjobGR.next()) {
                gs.info('HR SI record found ' + ghjob.getValue('u_jobcodehris'))
				//var objReturn = {
				//	jobcodeHRIS : ghjobGR.JobCodeHRIS.toString()
				//};
				//return JSON.stringify(objReturn);
				return ghjobGR.u_jobcodehris;
			}
			else {
                gs.info('HR SI record not found')
				return 'nothing';
			}	
		}
		catch(e) {
			return 'error' + e;
		}		
	},
    type: 'HRTT4UTicket'
});

If you are finding that the logged field value is null, undefined, or empty and have confirmed that it indeed is not for the same record, ensure that the user the script is running as has the User role specified in the Controls tab of your custom table definition.  When making any kind of access change, be sure to end impersonation or log out before re-testing.  Confirm that the user the script is running as can view the record retrieved by the GlideRecord.