- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2015 04:18 PM
I am running the script below in the Approval Request email notification's advanced condition section. This condition is running on the Approval table for Approval requests related to Knowledge articles. I created a new True/False field on the Knowledge form called expiring, if the box(field) is checked then I do not want the Approval request notification to be sent. I am having a difficult time getting this to work, any help would be appreciated. The system seems to see the u_expiring's field value as false every single time.
expireso();
function expireso() {
var exp = new GlideRecord("kb_knowledge");
exp.addQuery('sys_id', current.document_id);
exp.query();
var answer;
if ((exp.u_expiring) == "true") {
answer = false;
}
else {
answer = true;
}
return answer;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2015 02:52 PM
Thanks Brad and Julian for your help. I worked with support because nothing seemed to work. The real cause of the issue was the fact that the Approval Request was being generated even before the Knowledge article actually existed at the database level. I resolved this by adding a timer to delay the start of the generation of the approval request by 2 seconds in the workflow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2015 06:03 PM
Hi Bobby,
The issue is that you need a .next() line.
expireso();
function expireso() {
var exp = new GlideRecord("kb_knowledge");
exp.addQuery('sys_id', current.document_id);
exp.query();
var answer;
if (exp.next()) {
if (exp.u_expiring == true) {
answer = false;
} else {
answer = true;
}
}
return answer;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2015 07:46 AM
I had the .next part in there before and took it out because it did not work. I tried it again and it still does not work. I went through the script and commented out different areas and I have come to the conclusion that the system is not processing the if statement correctly. Can you think of anything else that might cause this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2015 07:53 AM
try this
expireso();
function expireso() {
var answer;
var exp = new GlideRecord("kb_knowledge");
if (exp.get(current.document_id))
{
if (exp.u_expiring == 'true')
return false;
else
return true;
}
or this which embeds the true statement into the query
expireso();
function expireso() {
var answer;
var exp = new GlideRecord("kb_knowledge");
exp.addQuery('sys_id',current.document_id)
exp.addQuery('u_expiring',true);
exp.query();
if (exp.next())
return false;
else
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2015 09:39 AM
Julian I appreciate your help. I tried both scripts that you provided and neither worked. I do want to share some troubleshooting that I have done. To make sure that the query is pulling the right information I created the business rule shown below on the Approval form. I simply wanted to ensure that values were being retrieved and they are as shown in the attached screen shot. This is weird.
expireso();
function expireso() {
var exp = new GlideRecord("kb_knowledge");
exp.addQuery('sys_id', current.document_id);
exp.addQuery('u_expiring', "true");
exp.query();
var answer = true;
while (exp.next()) {
// if (exp.u_expiring == true) {
// answer = false;
// }
// else {
// answer = true;
// }
// }
// gs.addInfoMessage("The number is " + exp.sys_id + " This is the currentid " + current.document_id);
gs.addInfoMessage("The number is " + exp.sys_id + " This is the currentid " + current.document_id + " Record count " + exp.getRowCount());
gs.addErrorMessage("Expiring value with get is " + exp.u_expiring);
}
}