- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 02:40 PM
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>');
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 03:18 PM
sys_id is a property on the current object that holds the sys_id of the record. Did you try current.getLink()?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 02:54 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 02:58 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 03:01 PM
You should still be able to use current from the mail script. You're actually doing it with current.sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 03:04 PM
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"