The CreatorCon Call for Content is officially open! Get started here.

How to check for approvals on an RITM from the Service Catalog Request workflow?

Laurie Marlowe1
Kilo Sage

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.

find_real_file.png

Any ideas?

Thank you,

Laurie

 

 

 

 

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

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

View solution in original post

5 REPLIES 5

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?