Dynamic Child task number

Community Alums
Not applicable

Hello,

I have a requirement to generate the custom/dynamic task number. I have a custom application where the parent request from creates 9 child tasks (task table is extended from OOB task table) here the child task number should should thing like "TASK- +Parent Number- + 01" the last two digests should go from 01 to 09. Please let me know if this is something doable?

 

Thanks,

Prudhvi 

1 ACCEPTED SOLUTION

@Community Alums 

you can use a flow variable to hold the counter and then re-use it in the next loop.

increment the flow variable with each loop

check this gif below, attaching it again to the comment

AnkurBawiskar_0-1748839153010.gif

 

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

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

yes this is possible via scripting.

something like this in server side

// Assume parentGr is the GlideRecord of the parent request
var parentNumber = parentGr.number; // Or whatever field holds the parent number

for (var i = 1; i <= 9; i++) {
    var childGr = new GlideRecord('x_yourapp_child_task'); // Replace with your table name
    childGr.initialize();
    childGr.parent = parentGr.sys_id; // Or the relevant parent field
    // Generate two-digit sequence
    var seq = ('0' + i).slice(-2);
    childGr.u_custom_number = 'TASK-' + parentNumber + '-' + seq;
    // Set other fields as needed
    childGr.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

Community Alums
Not applicable

Hi @Ankur Bawiskar - I am creating the task from flow designer and setting few fields from parent to child and  trying to set the number value from flow designer script but it's not setting the value.

prudhvirajy_4-1748837381603.png

 

 

 

@Community Alums 

you can use a flow variable to hold the counter and then re-use it in the next loop.

increment the flow variable with each loop

check this gif below, attaching it again to the comment

AnkurBawiskar_0-1748839153010.gif

 

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

YaswanthKurre
Giga Guru

Hi @Community Alums ,

 

In flow designer you have to iterate 9 times  and create a record for each iteration, you are just iterating inside a variable and doing some random  update, this will not work.

 

Make sure you design your flow as @Ankur Bawiskar's script.

 

Thanks,

yaswanth.