- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 07:34 AM
The notification "Notify attestation recipient" on the Assessment Instance [asmt_assessment_instance] table emails the recipients when an attestation is executed.
My goal is to have an email script which queries the Knowledge [kb_knowledge] table for a KB with the same short_description as the assessment's metric_type. Below is what I have in my email script. No matter what code I use, I either get ALL of the KBs or nothing. Any help will be appreciated! Thank you.
EMAIL SCRIPT:
template.print("<br />");
var gr = new GlideRecord("kb_knowledge");
gr.addQuery('short_description', current.sys_id);
gr.query();
while (gr.next()) {
var link = new GlideSubstituteURL().generateURL(gr, '');
var title = gr.number;
if (gr.short_description == metric_type.name) {
title+= " - " + gr.short_description;
}
var anchor = "<a href='" + link +"'>" + title + "</a>";
template.print(anchor + "<br />");
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 07:51 AM
Shane,
With just a basic look at your script, line 03 is querying for where short_description is a sys_id value. I would expect that to always return 0 records, however in many cases, a poorly written addQuery() command does not error out, but is just ignored. This is a common issue resulting in getting "all" records.
I also do not see "metric_type" defined anywhere. (line 08). This the if statement may always return false.
last, I am not sure if you need to encodeURIComponent or not on the link before using it in your anchor.
Hopefully these tips help.
-Ken
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 07:51 AM
Shane,
With just a basic look at your script, line 03 is querying for where short_description is a sys_id value. I would expect that to always return 0 records, however in many cases, a poorly written addQuery() command does not error out, but is just ignored. This is a common issue resulting in getting "all" records.
I also do not see "metric_type" defined anywhere. (line 08). This the if statement may always return false.
last, I am not sure if you need to encodeURIComponent or not on the link before using it in your anchor.
Hopefully these tips help.
-Ken
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 08:27 AM
Ken - Thank you for your help. The script below worked!!
template.print("<br />");
var mt = current.metric_type.name;
var gr = new GlideRecord("kb_knowledge");
gr.addQuery('short_description', mt);
gr.query();
while (gr.next()) {
var link = new GlideSubstituteURL().generateURL(gr, '');
var title = gr.number;
if (gr.short_description != '') {
title+= " - " + gr.short_description;
}
var anchor = "<a href='" + link +"'>" + title + "</a>";
template.print(anchor + "<br />");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 09:51 AM
One last thing on this. The link to the KB article opens the edit view of the KB. Does anyone know how to link to the ess view of the article?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 10:39 AM
Try a URL similar to this: https://devnnnn.service-now.com/ess/knowledge.do?sysparm_document_key=kb_knowledge,08f78d43ff1131009...