- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 12:51 AM - edited 03-06-2023 12:54 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 11:55 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 01:14 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 01:21 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 03:21 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 11:36 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 11:55 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader