- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2016 01:43 PM
Hello Everyone,
I'm not sure if what I'm asking is even possible.
I want to create multiple tasks based on selections in the request item. This is for a 'User Leaving' request.
The requestor will select from a list of applications (Checkboxes on the catalog item).
I want to create a catalog task for each of the applications selected. We do currently do this using a switch and multiple 'Catalog Task' activities. My problem is that the list of applications is constantly changing and I dont want to spend my time updating the workflow, adding conditions and catalog tasks. I want it to be dynamic so when an application is added to the list.... the workflow will not need to be touched.
I'm open to all suggestions
Thanks
Harry
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2016 04:27 PM
Hello,
Great! Glad I could help.
Im not sure how I would script the wait for condition to wait for the tasks to complete. How would I go about this?
Simplest tricks are the best tricks, I say. Simply run a GlideRecord query in the wait for condition script that looks for all records in the sc_task table whose parent is "current.getValue('sys_id')" (the sys_id of the RITM) and see if any of them are still open.
In fact, you can do that with a single query if you do something like this...
var openStateValues = []; //Add the integer values for all non-closed states here. You could also do the opposite and change the "IN" to "NOTIN" below.
var gr = new GlideRecord('sc_task');
gr.addQuery('parent', current.getValue('sys_id'));
gr.addQuery('state', 'IN', openStateValues);
gr.query();
answer = gr.hasNext();
Then set up an "After" BR on the sc_task table that'll run on any record where (with "show related fields" turned on in the business rule condition picker) parent.cat_item is (the catalog item you're referring to) and then "state, changes to, [one of the closed states]". Then have it simply do something like....
var parentgr = parent.getRefRecord();
parentgr.work_notes = current.getValue('number') + ' closed.';
parentgr.update(); //This will kick the workflow, triggering the re-evaluation of the condition.
Regarding the list collector, yes, you can auto-pop some values. Just push in an array or, if it's being finicky, a comma-separated string (just call .toString() on an array if you need to) of sys_IDs.
Don't forget to mark my answers as correct/helpful if I was able to help you out. 🙂 Thanks mate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2016 03:37 PM
Hmm, well -- So if I understand your need correctly, you're looking to create a task for each selected option in a given variable. Is that right?
If so, a simple for loop would surely fit your need, no?
Rather than using the "create task" workflow activity, you could simply script out the creation of the catalog task - assigning the necessary values, such as parent manually - and if you needed to wait for these tasks to each finish, you could simply use "wait for condition". Just be aware that in order for the "wait for condition" script to be re-evaluated, the record on which the workflow is running (the RITM) must be updated. You can give the workflow a little "kick" by having a script add a comment to the parent RITM whenever such a task is completed.
I think I heard rumor of Helsinki introducing multiple tickboxes under one catalog variable as an option, but outside of that you may want to consider using something other than tick-boxes for this, so it can be easily iterated over. A list collector for example, would be a great choice.
Does this answer your question, or am I way off base? Let me know and I'll be glad to give you another answer if I've missed something.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2016 04:04 PM
I think you have hot the nail on the head with my requirements. A list collector with a loop could definitley work. Just a couple of questions:
Im not sure how I would script the wait for condition to wait for the tasks to complete. How would I go about this?
If using a list collector, I would have a requirement for some of the applications to be auto selected based on the users department, is this possible? I would assume so.
Thanks
Harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2016 04:27 PM
Hello,
Great! Glad I could help.
Im not sure how I would script the wait for condition to wait for the tasks to complete. How would I go about this?
Simplest tricks are the best tricks, I say. Simply run a GlideRecord query in the wait for condition script that looks for all records in the sc_task table whose parent is "current.getValue('sys_id')" (the sys_id of the RITM) and see if any of them are still open.
In fact, you can do that with a single query if you do something like this...
var openStateValues = []; //Add the integer values for all non-closed states here. You could also do the opposite and change the "IN" to "NOTIN" below.
var gr = new GlideRecord('sc_task');
gr.addQuery('parent', current.getValue('sys_id'));
gr.addQuery('state', 'IN', openStateValues);
gr.query();
answer = gr.hasNext();
Then set up an "After" BR on the sc_task table that'll run on any record where (with "show related fields" turned on in the business rule condition picker) parent.cat_item is (the catalog item you're referring to) and then "state, changes to, [one of the closed states]". Then have it simply do something like....
var parentgr = parent.getRefRecord();
parentgr.work_notes = current.getValue('number') + ' closed.';
parentgr.update(); //This will kick the workflow, triggering the re-evaluation of the condition.
Regarding the list collector, yes, you can auto-pop some values. Just push in an array or, if it's being finicky, a comma-separated string (just call .toString() on an array if you need to) of sys_IDs.
Don't forget to mark my answers as correct/helpful if I was able to help you out. 🙂 Thanks mate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2016 01:11 AM
This worked perfectly, thank you Timothy!!