GlideRecord not querying table

EdwinCoronado
ServiceNow Employee
ServiceNow Employee

Hello I have this code that is querying a table called "hr_case". This is a Mail Script that is called on an email notification. However, it is not working. It is not properly querying. I tried "template.print(current.sys_id)" and it is properly returning the sys id, however, the query is not getting executed properly. I tried adding something like "template.print("RECORD FOUND");" inside the "if" scope to see if the record was being found but it is not. I tried passing a hard-coded sys-id for an incident and changed the queried table to 'incident' and that one DOES work. So it seems that the issue is only with the "hr_case" table. I also tried changing the "next()" and "query()" methods to "_next()" and "_query()" just in case there was a field in the table called next or query. Please let me know if you have any ideas. Thanks.

  var link = '';

  var rec = new GlideRecord('hr_case');

  rec.addQuery('sys_id', current.sys_id);

  rec.query();

  if(rec.next()){

  link = gs.getProperty('glide.servlet.uri') + 'nav_to.do?uri=' + rec.getLink();

  }

  var pos = link.indexOf('sys_id');

  var ess_link = link.substring(0,pos) + 'sysparm_view=ess%26' + link.substring(pos);

  template.print('<a href="' + ess_link + '">${number}</a>');

1 ACCEPTED SOLUTION

sys_id is a property on the current object that holds the sys_id of the record. Did you try current.getLink()?


View solution in original post

6 REPLIES 6

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Edwin,



I don't quite understand why you're trying to do a gliderecord query for the current record when you can just use the current object.


Hi Brad, I totally forgot to mention but this script is a Mail script that get's called in an email notification. So that's why I'm querying the table.


You should still be able to use current from the mail script. You're actually doing it with current.sys_id.


I don't think so because I need to create a GlideRecord object in order to be able to call the getLink() function. I tried doing "template.print(current.sys_id.getLink())" and it returned "undefined"