- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2025 07:29 AM
I have an IF activity in a catalog workflow that is not giving expected results.
answer = ifScript();
//
function ifScript() {
workflow.scratchpad.count = workflow.scratchpad.count + 1;
var flag = 0;
gr = new GlideRecord("u_database_termination_data_details");
gr.addEncodedQuery("u_ritm=" + current.number);
gr.query();
if (!gr.next()) {
return 'no';
}
else if (gr.next()) {
return 'yes';
}
}
This is the table in question-
I did edit this record so the RITM# would match. What am I missing that the above IF is returning No when the query done manually works?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2025 07:40 AM
Hello @jlaps
Your script has a logical error where gr.next() is called twice. The correct way to check for records is to call gr.next() once within the if condition.
answer = ifScript();
//
function ifScript() {
workflow.scratchpad.count = workflow.scratchpad.count + 1;
var flag = 0;
gr = new GlideRecord("u_database_termination_data_details");
gr.addEncodedQuery("u_ritm=" + current.number);
gr.query();
if (!gr.next()) {
return 'no';
}
else {
return 'yes';
}
}
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2025 07:40 AM
Hello @jlaps
Your script has a logical error where gr.next() is called twice. The correct way to check for records is to call gr.next() once within the if condition.
answer = ifScript();
//
function ifScript() {
workflow.scratchpad.count = workflow.scratchpad.count + 1;
var flag = 0;
gr = new GlideRecord("u_database_termination_data_details");
gr.addEncodedQuery("u_ritm=" + current.number);
gr.query();
if (!gr.next()) {
return 'no';
}
else {
return 'yes';
}
}
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2025 08:52 AM
Since you just want to check if record is present or not better to use hasNext() method.
try this
-> if record not found then output is no
answer = ifScript();
function ifScript() {
workflow.scratchpad.count = workflow.scratchpad.count + 1;
var flag = 0;
var gr = new GlideRecord("u_database_termination_data_details");
gr.addEncodedQuery("u_ritm=" + current.number);
gr.query();
if (!gr.hasNext()) {
return 'no';
} else {
return 'yes';
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader