
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2013 06:55 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2013 11:50 PM
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 as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2013 07:20 PM
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 as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2013 07:32 PM
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';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2013 11:50 PM
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 as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2013 07:54 PM
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 as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2013 08:19 PM