- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2020 02:02 PM
Hello,
We have a requirement for some catalog items to obtain the supervisor's approval on the RITM before the Service Catalog Request workflow goes through the Technology approval. I am having an issue with the second loop if (ap.next()) not finding the record. For my log statement it says "ap is no". I tried various things, such as running a background script and hard coding the RITM number, which did not work. I tried going to the sysapproval_approver table and creating a query with state = requested .and. Approved for.number = <RITM number> and this returns the record.
// Set the variable 'answer' to true or false to indicate if the condition has been met or not.
var found = 'no';
var num = '';
var itm = new GlideRecord('sc_req_item');
itm.addQuery('request', current.sys_id);
itm.addQuery('request_item.cat_item.u_no_it_review_approvals', false);
itm.addQuery('request_item.cat_item.u_no_ps_approval', false);
itm.addQuery('state', '!=', '3');
itm.addQuery('state', '!=', '4');
itm.query();
while (itm.next()) {
num = itm.number;
gs.log('number is ' + num);
}
var ap = new GlideRecord('sysapproval_approver');
ap.addQuery('state', 'requested');
ap.addQuery('sysapproval.number', num);
ap.addQuery();
if (ap.next()) {
found = 'yes';
gs.log('in second loop' + num);
}
gs.log('ap is ' + found);
if (found == 'yes') {
answer = false;
} else {
answer = true;
}
The workflow just passes through the Wait for condition for Additional RITM Approvals.
Any ideas?
Thank you,
Laurie
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2020 02:52 PM
Update your code like below
// Set the variable 'answer' to true or false to indicate if the condition has been met or not.
var found = 'no';
var num = '';
var itm = new GlideRecord('sc_req_item');
itm.addQuery('request', current.sys_id);
itm.addQuery('request_item.cat_item.u_no_it_review_approvals', false);
itm.addQuery('request_item.cat_item.u_no_ps_approval', false);
itm.addQuery('state', '!=', '3');
itm.addQuery('state', '!=', '4');
itm.query();
while (itm.next()) {
num = itm.number;
gs.log('number is ' + num);
}
var ap = new GlideRecord('sysapproval_approver');
ap.addQuery('state', 'requested');
ap.addQuery('document_id', current.sys_id);
ap.addQuery();
while(ap.next()) {
found = 'yes';
gs.log('in second loop' + num);
}
gs.log('ap is ' + found);
if (found == 'yes') {
answer = false;
} else {
answer = true;
}
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2020 02:52 PM
Update your code like below
// Set the variable 'answer' to true or false to indicate if the condition has been met or not.
var found = 'no';
var num = '';
var itm = new GlideRecord('sc_req_item');
itm.addQuery('request', current.sys_id);
itm.addQuery('request_item.cat_item.u_no_it_review_approvals', false);
itm.addQuery('request_item.cat_item.u_no_ps_approval', false);
itm.addQuery('state', '!=', '3');
itm.addQuery('state', '!=', '4');
itm.query();
while (itm.next()) {
num = itm.number;
gs.log('number is ' + num);
}
var ap = new GlideRecord('sysapproval_approver');
ap.addQuery('state', 'requested');
ap.addQuery('document_id', current.sys_id);
ap.addQuery();
while(ap.next()) {
found = 'yes';
gs.log('in second loop' + num);
}
gs.log('ap is ' + found);
if (found == 'yes') {
answer = false;
} else {
answer = true;
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2020 11:59 AM
Hi Sachin,
Now the problem seems to be that the "found = 'yes' is never set. For some reason it does not go into the while loop.
I tried this in a background script and it still won't work. "ap is no" is what prints. I verified there are two records that meet the condition for the query.
var found = 'no';
var ap = new GlideRecord('sysapproval_approver');
ap.addQuery('state', 'requested');
ap.addQuery('document_id', 'ec5245791b8ce4103efe8480cd4bcb71');
ap.addQuery();
if(ap.next()) {
found = 'yes';
gs.print('in second loop' + num);
}
gs.print('ap is ' + found);
Any ideas?
Thank you,
Laurie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2020 12:13 PM
I figured it out!
ap.addQuery();
if(ap.next()) {
I should be ap.query() not ap.addQuery().
Thank you very much for your help!
Laurie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2020 12:14 PM
Yes, i was about to point it out.
Code will work for you.
Regards,
Sachin