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

Ankur Bawiskar
Tera Patron
Tera Patron

@Apurv Kumar 

when you want child records to be created?

you can have after insert/update BR on parent and have the logic defined.

what did you start with and where are you stuck?

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

I am trying to take values from a field on parent record ie.u_type_of_work

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

{

  for(i=0;i<vastIds.length;i++)

   {

var newTask = new GlideRecord('child_table');

newTask.initialize();

newTask.u_task_type = "xyz";

newTask.insert();

}

}

I created an after insert BR and not able to create the new task records with above code..Kindly help

@Apurv Kumar 

try this

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.insert();
}
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Harsh_Deep
Giga Sage
Giga Sage

Then you can store that number in any variable and while creating a new task just add the value of that variable into short_description.

Mark as correct if it will helpful.