Create multiple tasks for one catalog item

dibeenapearl
Giga Contributor

Hi,

I have created a catalog item which has a list variable. This list variable is used to select users from the user table.

What I am trying to achieve: when the RITM gets approved, it should create a task for each user in the list variable.

Attempts did: I tried to create the task from the workflow using "Run Script". It did create the required number of tasks for one RITM, but I cannot see any variables of the RITM in the Variable tab of TASK.

The script I used to create task is:

//users = list variable

//

var a=current.variables.users;

var a_split=a.toString().split(',');

for(var i=0;i<a_split.length;i++)

{

var gt=new GlideRecord('sc_task');

gt.initialize();

gt.short_description='task created: '+i;

gt.request_item=current.sys_id;

gt.assignment_group.setDisplayValue('Client Support');

gt.parent = current.sys_id;

gt.insert();

}

Please find the RITM and TASK screenshot attached.

I would prefer the variables to appear on the variable Tab, but also the "Requested for:" should have only the user from the list variable. Is it possible?

Thanks,

Dibeena

10 REPLIES 10

gdd
Giga Expert

requested for field on the RITM and Task is coming from request, it will be always dot walk field.



check global checkbox on the variables it will show on the task


dibeenapearl
Giga Contributor

Thanks, Girish. I made the variables global and now I can see the variables in the TASK.


PrashantLearnIT
Giga Sage

Hi Dibeena,



Can you please share Run Script code you have used?


********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

//users = list variable


//


var a=current.variables.users;


var a_split=a.toString().split(',');


for(var i=0;i<a_split.length;i++)


{


var gt=new GlideRecord('sc_task');



gt.initialize();


gt.short_description='task created: '+i;


gt.request_item=current.sys_id;


gt.assignment_group.setDisplayValue('Client Support');


gt.parent = current.sys_id;


gt.insert();


}