- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2016 12:15 PM
Hi Everyone,
I had a requirement to create number of catalog tasks in my workflow dynamically.
When I say dynamically, I mean number of tasks to be created was determined number of values in a list collector variable of the catalog item.
Obviously, one cannot leverage CATALOG TASK activity in their workflow to achieve this. But, SC_TASK table can be glided using a RUN SCRIPT activity in the workflow.
When the SC_TASK is glided for creating those tasks, catalog task variables cannot be displayed on such tasks as you don't have option to add the variables to be displayed on the form like you do with a CATALOG TASK activity.
Since I could not add those variables, client scripts expecting those variables on the form were causing the form to come stand still (users were not able to even update work notes on task. all they could do was CLOSE the TASK).
To address this, I came up with a piece of code which worked out well to bring those variables on to sc_task form. Below is the code which creates number of tasks dynamically and includes variables on task. Hope this helps in resolving similar issues for SNOW community.
****************************************************************************************************************************************************************************************************
createCatalogTasks();
function createCatalogTasks() {
var list = current.variables.list_collector_var1.toString();
var arrayList = list.split(",");
for (var idx = 0; idx < arrayList.length; idx++) {
var catalogItem = new GlideRecord('sc_cat_item');
if (catalogItem.get(arrayList[idx])) {
var task = new GlideRecord('sc_task');
task.initialize();
task.request_item = current.sys_id;
task.short_description = 'My Task for ' + catalogItem.name;
task.assignment_group.setDisplayValue('MyGroup');
task.parent = current.sys_id;
task.state = 'OPEN'; //state is open
task.insert();
/*insert one variable on task form
var myVar = new GlideRecord('sc_item_variables_task');
myVar.initialize();
myVar.task = task.sys_id;
myVar.variable = 'kdjvndv23894u29385';//sys_id for the vairable from item_option_new table
myVar.insert();
//end of inserting one variable*/
//insert all catalog item variables on task form
var catVariables = new GlideRecord('item_option_new');
catVariables.addQuery('cat_item',current.cat_item);
catVariables.query();
while(catVariables.next()){
var myVar = new GlideRecord('sc_item_variables_task');
myVar.initialize();
myVar.task = task.sys_id;
myVar.variable = catVariables.sys_id;
myVar.insert();
}
//end of inserting all catalog item variables on task form
}
}
}
****************************************************************************************************************************************************************************************************
Solved! Go to Solution.
- 10,463 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2016 12:16 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2016 12:16 PM
Discussion already has the answer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 07:45 AM
Rajesh - if there was already a discussion, please provide a link to that discussion for others to follow. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 08:16 PM
Hi,
This post is very helpful for the similar situation in my project.
I am able to add the variables on the Task created thru a Transform script from excel file. But is not able to make it visible on the form or mandatory.
Please help
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2017 11:57 AM
Hello Rajesh,
Could you please direct me to the answer for this question,
Rahul Ashar