- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2016 03:23 PM
Hi: I'm not having any luck running 2 approvals in parallel within a request item. It seems that one approval has to finish before the second one starts. Is there a way around this? Like perhaps kick off 2 requests items within the master request item, or something along those lines?
Thank you! Rita
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2016 01:33 PM
Here is an example workflow layout to show you want I mean in the first paragraph above about having a set number of groups and using If activities.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2016 12:47 PM
OK here is a quick and dirty working solution. Obviously I don't have visability into all the questions and answer variables you have on your catalog item so my example is very simple.
What I did was create a catalog item with just a list collector. This list collector goes against the Application Configuration Item table (cmdb_ci_appl) and displays those - made an assumption you may be doing something similar. The advantage of doing this is the CI (cmdb_ci) table has an attribute called Approval Group which I am leveraging in the workflow to know who to require for approval. Again made an assumption here.
Here is what the item looks like from the catalog:
So as you can see I chose two applications and then when I click order now, you will see I get two request items under my request:
So how did I do that? I edited the workflow to detect if there was more than 1 application selected and if so then loop through the list and create copies for each additional application:
Once I detect there is more than one application I reset the application list to just 1 so when the workflows start for the additional items they don't create these in circles. When the workflow runs for the additional applications selected, it will branch like this:
So here is the code from each activity:
More than 1 application selected? If Activity:
answer = ifScript();
function ifScript() {
if (current.variables.application_list.toString().split(",").length > 1) {
return 'yes';
}
return 'no';
}
Create Additional Request Items Run Script: Notice I set the CI of the request to each application as I will leverage that in the group approval.
var appArray = current.variables.application_list.toString().split(",");
// Copy first application into the CI field and clear out application list
current.configuration_item = appArray[0];
current.variables.application_list = appArray[0];
current.update();
// Start loop at the second position and create request item for each application
var reqItemCopy = new GlideRecord("sc_req_item");
var reqItemCopyList = [];
for (var i = 1; i < appArray.length; i++) {
// Create a copy of the requested item
reqItemCopy.initialize();
reqItemCopy.configuration_item = appArray[i];
reqItemCopy.request = current.request;
reqItemCopy.cat_item = current.cat_item;
reqItemCopy.short_description = current.short_description;
reqItemCopy.description = current.description;
reqItemCopy.price = current.price;
reqItemCopy.due_date = current.due_date;
var reqItemID = reqItemCopy.insert();
// Copy the variables
itemOptionM2M = new GlideRecord("sc_item_option_mtom");
itemOptionM2M.addQuery("request_item", current.sys_id);
itemOptionM2M.query();
while (itemOptionM2M.next()) {
var itemOption = new GlideRecord("sc_item_option");
itemOption.addQuery("sys_id", itemOptionM2M.sc_item_option.toString());
itemOption.query();
if (itemOption.next()) {
var itemOptionCopy = new GlideRecord("sc_item_option");
itemOptionCopy.item_option_new = itemOption.item_option_new;
itemOptionCopy.order = itemOption.order;
if (itemOption.item_option_new.name.toString() == "application_list") {
itemOptionCopy.value = appArray[i];
} else {
itemOptionCopy.value = itemOption.value;
}
var itemOptionCopyID = itemOptionCopy.insert();
var itemOptionM2MCopy = new GlideRecord("sc_item_option_mtom");
itemOptionM2MCopy.request_item = reqItemID;
itemOptionM2MCopy.sc_item_option = itemOptionCopyID;
itemOptionM2MCopy.insert();
}
}
reqItemCopyList.push(reqItemID + "");
}
workflow.scratchpad.reqitem_list = reqItemCopyList.toString();
Start Request Item Workflows Run Script:
var scReqItem = new GlideRecord("sc_req_item");
scReqItem.addQuery("sys_id", "IN", workflow.scratchpad.reqitem_list);
scReqItem.query();
while (scReqItem.next()) {
scReqItem.approval = "requested";
scReqItem.stage = "request_approved";
var w = new Workflow();
var context = w.startFlow(scReqItem.cat_item.workflow.toString(), scReqItem, "update", getVars(scReqItem));
if (context != null)
scReqItem.context = context.sys_id;
scReqItem.update();
}
/**
* Get the variables from the request item so that we can map these to the workflow.input
* variables if the names match.
*/
function getVars(scReqItem) {
var vars = {};
for (var n in scReqItem.variables)
vars[n] = scReqItem.variables[n];
return vars;
}
Group Approval - notice I dot walk to the CI's approval group:
I had to break up the creation of the request and starting of the workflow because I was getting errors that the current.variables.application_list was undefined if I had all of this in the same activity. So that is why you will see two run scripts.
Let me know if you have any questions! Have a nice weekend.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 08:12 AM
Hi Michael: I kind of see what you are doing. This is very creative, yet quite customized. Is sc_item_option_mtom the variables in the catalog item? Regards, Rita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 08:28 AM
The sc_item_option table stores the actual variable answers. It has a link to the catalog variable with the question text.
The sc_item_option_mtom table links these answers to the actual task (request item in this case).
It looks more complicated than it really is but its more flexible in that you can choose any number of applications versus being restricted to 3. You will still have the audit of having a request item for each application chosen.