
- 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-24-2013 10:27 PM
Can you share the snippet, what exactly you have written in IF Statement.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2013 07:57 PM
After you asked for the snipet I reviewed what I did line by line and found my error.
I can't thank you enough again.
I really appreciate you going above and beyond helping me resolve this issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2013 12:10 AM
No issues at all.. I am glad that you get the things working now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2019 07:41 AM
Hi Mark and Neetu
I have tried to same thing. But my rec.cat_item is coming as empty. Can you please help me? I have checked the log and got the following. I am new in servicenow and need help.
Log:
rec : {"sys_meta":{"active":"1","array":"0","attributes":"hasWorkflow=true","audit":"1","calculation":"","choice":"1","choice_field":"","choice_table":"","create_roles":"catalog_admin","default_value":"","delete_roles":"","dependent":"","dependent_on_field":"","display":"number","dynamic_creation":"0","dynamic_creation_script":"","dynamic_default_value":"","dynamic_ref_qual":"","element_reference":"0","filterable":"1","foreign_database":"","function_definition":"","function_field":"0","groupable":"1","help":"","hint":"","i18n_sortable":"1","internal_type":"collection","label":"Requested Item","language":"en","mandatory":"0","matchable":"1","max_length":"40","multi_text":"0","name":"sc_req_item","plural":"Requested Items","primary":"0","read_only":"0","read_roles":"","reference":"","reference_cascade_rule":"","reference_floats":"0","reference_key":"","reference_qual":"","reference_qual_condition":"","reference_type":"","sizeclass":"141","sortable":"1","spell_check":"0","staged":"0","sys_package":"c29a78195860130059a6b831cdd54e8d","sys_scope":"global","table_reference":"0","text_index":"1","type":"0","type_description":"collection","unique":"0","url":"","url_target":"","use_dynamic_default":"0","use_reference_qualifier":"simple","virtual":"0","widget":"","write_roles":"catalog,itil","xml_view":"0"},"parent":{},"made_sla":{},"watch_list":{},"sc_catalog":{},"upon_reject":{},"sys_updated_on":{},"approval_history":{},"number":{},"sys_updated_by":{},"opened_by":{},"user_input":{},"price":{},"sys_created_on":{},"recurring_frequency":{},"sys_domain":{},"context":{},"state":{},"sys_created_by":{},"knowledge":{},"order":{},"closed_at":{},"cmdb_ci":{},"delivery_plan":{},"backordered":{},"impact":{},"active":{},"work_notes_list":{},"business_service":{},"priority":{},"sys_domain_path":{},"time_worked":{},"rejection_goto":{},"expected_start":{},"opened_at":{},"business_duration":{},"group_list":{},"configuration_item":{},"work_end":{},"u_coc_status":{},"approval_set":{},"wf_activity":{},"work_notes":{},"order_guide":{},"request":{},"short_description":{},"correlation_display":{},"work_start":{},"delivery_task":{},"assignment_group":{},"additional_assignee_list":{},"description":{},"calendar_duration":{},"sys_class_name":{},"close_notes":{},"closed_by":{},"follow_up":{},"sys_id":{},"contact_type":{},"urgency":{},"company":{},"reassignment_count":{},"activity_due":{},"assigned_to":{},"variables":{"select_user":{},"server":{},"dns_domain":{},"user_guid":{},"user_staff_id":{}},"variable_pool":{"select_user":{},"server":{},"dns_domain":{},"user_guid":{},"user_staff_id":{}},"hierarchical_variables":{"start":{}},"quantity":{},"comments":{},"sla_due":{},"approval":{},"comments_and_work_notes":{},"due_date":{},"sys_mod_count":{},"recurring_price":{},"sys_tags":{},"billable":{},"cat_item":{},"stage":{},"escalation":{},"upon_approval":{},"correlation_id":{},"location":{},"estimated_delivery":{}}
The Code:
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
gs.log(' from work flow of to bypass***start ****');
gs.log (' count ' + count);
while (rec.next()) {
gs.log('rec : ' + JSON.stringify(rec));
gs.log('rec.cat_item : ' + JSON.stringify(rec.cat_item));
if (rec.cat_item == '248da860db003300bc2685184b961996')
{ 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
‎03-07-2019 07:12 AM
Kasturi,
I ended up changing my logic. I added a check box on my item form that says bypass manager approval. This way I dont have to script each time a new bypass item is created.
In my workflow I check with a workflow activity script to see if all items are checked as bypass manager approval and make an approval decision off that.