
- 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-20-2013 07:53 PM
I should add, it is possible for the requestor to add multiple categories to a request, so the "IF" script must ask ONLY is category = xyz. If more than one category is in the request, then proceed with approval.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2013 01:30 AM
OK, If you have a category that doesn't require any approval, then there must be one or multiple catalog items be placed under that category.
Write an Advanced IF Script like this in your workflow:
answer = ifScript();
function ifScript() {
if (current.cat_item == "sys_id of catalog item that comes under Loaner category" || current.cat_item == "sys_id of catalog item2 that comes under Loaner category".....)
{
return 'yes';
}
return 'no';
} // So the logic is , if it returns "yes" connect it to marked approved activity (set values = approved) else move it to approval required activity.
// Here, Am assuming that your workflow is running on request item form.
I hope this gives you exact solution to your problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2013 11:07 AM
Thank you
I tried the above script but always returned a yes.
I was also offer another script I tried and it seems very close but got an error. (See attached workflow pic and error msg.pic) I would appreciate any suggestion to resolve the attached error. Obviously my scripting capability is in beginner learning level. From the pic the error message is Fault " the "Req" in not defined.
answer = ifScript();
function ifScript() {
var rec = new GlideRecord('sc_req_item');
rec.addQuery('request', current.sys_id);
rec.query();
while (rec.next()) {
if (req.cat_item.category != '49d84ff7417f41003307c49932f92b2d') { // Temporary Loaner Hardware
return 'yes';
}
}
return 'no';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2013 11:20 PM
If I am not wrong, it seems that your workflow is running on Request table and a request can consist of more than one request item. Can u let me know - Does approvals applies to Request or a Request Item.
Anyways, I have revised your script :
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') { // Regarding workflow error :Problem is here, you used "req" instead of "rec".
return 'yes';
}
return 'no';
}
}