How can I bypass approval for a particular Service Category?

Mark_Bailey
Mega Guru

I have a category in my Service Catalog for Loaner Items. (PC Mice Etc.)
This category will not require an approval.
My default work flow for ALL Service Request is to go to the requested for manager and get approval.
I want to add an IF condition that states IF the only category on the request is the Loaner Category, then bypass the approval state. I was going to use an if statement in the workflow and use a custom script to do this. If the only category is "Loaner" then mark approved. Carry on forward form there.
Is there a better way to do this? Does anyone have a custom script similar to what I am try to do I can borrow and customize to my category?

Thank you.

1 ACCEPTED SOLUTION

neetusingh
Giga Guru

So According to your logic, If your request contains loaner category's item along with any other Category's item, then it should go for approval. Right, So I hope below script resolves your query. Write this script in your Advance IF Activity in workflow :

var count = 0;
var c = 0;
answer = ifScript();
function ifScript() {
var rec = new GlideRecord('sc_req_item');
rec.addQuery('request', current.sys_id); // finding all related Request Items corresponding to the current Request
rec.query();
count = rec.getRowCount(); // getting the number of items raised within a request

while (rec.next()) {
if (rec.cat_item.category == '49d84ff7417f41003307c49932f92b2d')
{ c = c+1; // Making the count of the number of Items raised from the Loaner category
}
}

if(c != count) // If Request consist of item along with Loaner category's item, then Go for Approval
{ return 'yes';
}
else { // If request consist of only Loaner Category's item, then skip approval
return 'no';
}
}


View solution in original post

16 REPLIES 16

Mark_Bailey
Mega Guru

Neetu,

Thank you so much for your help.

The goal of my endeavor is to have the script ask at the request level, if the ONLY category on the request level is the "Loaner Hardware" then bypass approval for the entire request. If the Request is anything other than loaner, the go for approval. If the Request contains Loaner and something else, then go for approval.

The approval will be bypassed at the request level ONLY if the category of item is ONLY "Loaner".


Mark_Bailey
Mega Guru

This script is very close.
If the request contains the "loaner category" then it bypasses the approval.
But if the request has "Loaner Category" AND other categories, it still bypasses the approval.

answer = ifScript();
function ifScript() {
var rec = new GlideRecord('sc_req_item');
rec.addQuery('request', current.sys_id);
rec.query();
while (rec.next()) {
if (rec.cat_item.category != '49d84ff7417f41003307c49932f92b2d') {
return 'yes';
}
return 'no';
}
}


neetusingh
Giga Guru

So According to your logic, If your request contains loaner category's item along with any other Category's item, then it should go for approval. Right, So I hope below script resolves your query. Write this script in your Advance IF Activity in workflow :

var count = 0;
var c = 0;
answer = ifScript();
function ifScript() {
var rec = new GlideRecord('sc_req_item');
rec.addQuery('request', current.sys_id); // finding all related Request Items corresponding to the current Request
rec.query();
count = rec.getRowCount(); // getting the number of items raised within a request

while (rec.next()) {
if (rec.cat_item.category == '49d84ff7417f41003307c49932f92b2d')
{ c = c+1; // Making the count of the number of Items raised from the Loaner category
}
}

if(c != count) // If Request consist of item along with Loaner category's item, then Go for Approval
{ return 'yes';
}
else { // If request consist of only Loaner Category's item, then skip approval
return 'no';
}
}


Mark_Bailey
Mega Guru

Oh my god, I am jumping up and down hitting my head on the ceiling.
I thank thank thank you 200%.
This script did it. I have been needing to take this off my to do list for a long time.
I owe you! Thank you so much for all the support. You rock!


Mark_Bailey
Mega Guru

Although it worked fine, it did throw a fault error. Attach image.
Should I be concerned with that?