Creating Catalog Task through Run Script

Swarnika1
Tera Expert

Hello All,

 

I have created a workflow using RunScript to create a catalog Task. Whenever I am submitting the Catalog, due to the workflow the task is getting created in sc_task table but is not attaching in the related list of RITM, which earlier used to happen when I did it without Run Script. Am I missing something here?

Please Help!

1 ACCEPTED SOLUTION

prasannaposetty
Tera Expert

As Tripti mentioned, its good to use Catalog Task block instead of runscript.

To your query, in the runscript after initializing the gliderecord you need add the below line gr.request_item = current.sys_id;

View solution in original post

3 REPLIES 3

Trupti6
Tera Expert

Why you are using Run Script activity to create catalog task, instead of Run script you can use catalog task which is OOB functionality.

find_real_file.png

prasannaposetty
Tera Expert

As Tripti mentioned, its good to use Catalog Task block instead of runscript.

To your query, in the runscript after initializing the gliderecord you need add the below line gr.request_item = current.sys_id;

Sumedh Kharode1
Kilo Expert
You can check below code also in run script to create a task:

 

 var gt = new GlideRecord('sc_task');
gt.initialize();
gt.request_item = current.sys_id;
gt.short_description = 'Short description';
gt.setDisplayValue('assignment_group' ,'Some Assignment Group');
gt.description ='Description of Task';
gt.u_task_duration = '2d';
var task_sys_id = gt.insert();
createVariables(task_sys_id);



function createVariables(task_sys_id)
{

var tsk = new GlideRecord('sc_task');
tsk.addQuery('sys_id',task_sys_id);
tsk.query();
while (tsk.next())
{

var reqvar = new GlideRecord('sc_item_option_mtom');
reqvar.addQuery('request_item',current.sys_id);
reqvar.query();

while (reqvar.next())
{

var variablereference = new GlideRecord('sc_item_option');

if (variablereference.get(reqvar.sc_item_option))
{

var add_task_var = new GlideRecord('sc_item_variables_task');
add_task_var.task = tsk.sys_id;
add_task_var.variable = variablereference.item_option_new;
add_task_var.insert();
}
}
}

}