Creation of task with a comma separated field value

Apurv Kumar
Tera Expert

I need to create tasks on basis of a comma separated field values.

 

I have a field in parent table of type "string" having input as 123,456,789.....Now i need to create task in the child table with these input in the short description of the task

1 ACCEPTED SOLUTION

@Apurv Kumar 

then update the field on child which holds parent

var vastIds = current.parent_record.u_type_of_work.toString().split(',');

for(var i=0; i<vastIds.length; i++)
{
	var newTask = new GlideRecord('child_table');
	newTask.initialize();
	newTask.u_task_type = "xyz";
	newTask.u_parentField = current.sys_id;
	newTask.insert();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Apurv Kumar
Tera Expert

I have a table A under which i have a field of type string (123,456,789....as input) and a task X under that table. When i open that task X, there is another table under task X. The 3rd table should have as many records created as we have values in the string field.

If that is referenced field then you can store all the values in one variable using .getValue.toString()
Then you can save your X task on the basis of 3rd table when ever in 3rd table any record is inserting

snegi
Giga Contributor
var Ids= current.parent.u_type_of_work.toString().split(',');

for(var i=0; i<Ids.length; i++)
{
	var newTask = new GlideRecord('child_table');
	newTask.initialize();
	newTask.u_task_type = "xyz"; // if you need the task type to update
        newTask.short_description = Ids[i]; // this will create that number of task which each comma separated short description
	newTask.insert();
}

Apurv Kumar
Tera Expert

Thanks for your help @Ankur Bawiskar ...

The only thing i need to add in the code is current.sys_id of the parent record in order to create child under it.

 

Thank you

@Apurv Kumar 

then update the field on child which holds parent

var vastIds = current.parent_record.u_type_of_work.toString().split(',');

for(var i=0; i<vastIds.length; i++)
{
	var newTask = new GlideRecord('child_table');
	newTask.initialize();
	newTask.u_task_type = "xyz";
	newTask.u_parentField = current.sys_id;
	newTask.insert();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader