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

Sandeep Rajput
Tera Patron
Tera Patron

@bigbacon I see an issue with your code here

return ghjobGR.JobCodeHRIS;

What exactly is JobCodeHRIS here? Is it a field name? If yes then probably you are trying to access the field using field label and not the field name.

Assuming your field name is u_job_code_hris your return should be as follows.

return ghjobGR.getValue('u_job_code_hris'); //Replace u_job_code_hris with correct field name

Hope this helps.

It actually doesn't matter, the entire record is always empty so every field's value is empty. It never actually get a record back even though it is looking up a valid item by sys_id

@bigbacon If 

			if(ghjobGR.next()) {

 Is executing which means the object definitely has some values.

 

How are you verifying if the record is empty? 

 

I still recommend you to change the way you are a accessing the field 

return ghjobGR.JobCodeHRIS;

 it should be either

return ghjobGR.u_job_code_hris; 

or 

return ghjobGR.getValue('u_job_code_hris'); //Replace u_job_code_hris with correct field name

I can have it send back the jsonified string of the object from the .get or .next and it comes back with empty fields like it can't find something. 

So thiss gets rteturned.

{"sys_meta":null,"u_jobcodehris":{},"u_istemplate":{},"sys_mod_count":{},"u_requisition_id":{},"sys_updated_on":{},"sys_tags":{},"sys_id":{},"u_jobname":{},"sys_updated_by":{},"u_id":{},"sys_created_on":{},"u_status":{},"sys_created_by":{}}