- 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-24-2020 01:44 PM
Hi Sachin,
Maybe you can help me again. I cannot figure out why this will not go into the loop and set answer = false! I verified the approval record is there on the RITM, but the workflow just continues as if there is not a requested approval record.
// Set the variable 'answer' to true or false to indicate if the condition has been met or not.
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()) {
var ap = new GlideRecord('sysapproval_approver');
ap.addQuery('state', 'requested');
ap.addQuery('document_id', current.sys_id);
ap.query();
if (ap.next()) {
gs.log('im in the loop');
answer = false;
} else {
answer = true;
}
}
Any ideas?