Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

dibeenapearl
Giga Contributor

I have found the solution finally.



I was able to update each user's name in the short description.



I created the below client script which applies only to Catalog Tasks when the tasks are loaded


************************************************************************


function onLoad() {


    //Type appropriate comment here, and begin script below


    var desc = g_form.getValue('short_description');


var short_desc = desc.split(':');



g_form.setValue('usr',short_desc[1]);



   


}



*******************************************************************



I split the short description of the Task and copied the user's name on the field. It is getting updated accordingly.



my short description was "Access requested for: Bailey Asher". I split with ':' and copied "Bailey Asher" to the catalog field "usr".



Please close this conversation as "Answered" as I am not able to close it.



Thanks,


Dibeena