Create second task based on First task closure for user A - workflow

Ankita9793
Tera Contributor

Hi All,
I have a requirement where multiple tasks gets created through run script for each MRVS row.
Whenever a user’s 1st task/Genesys task is completed, SNOW must automatically create a new task for Media Recording team for that same user. This should happen for every user in the request in the sequence of his task closure. Please suggest. 

Example – Users – A, B, C

Genesys task created –

  • SCTASK001 – User A – Genesys
  • SCTASK002 – User B – Genesys
  • SCTASK003 – User C – Genesys

When Genesys completes for User B first:

  • SCTASK002 Closed – Create SCTASK004 (User B – Media Task)

When Genesys completes User A later:

  • SCTASK001 Closed - Create SCTASK005 (User A – Media Task)

When Genesys completes User C last:

  • SCTASK003 Closed Incomplete - No Media task to be created

 

RUN Script : 

var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.getUniqueValue());
rec.addQuery('state', '3');
rec.addQuery('active', 'false');
rec.query();
if (rec.next()) {
    gs.print('rec.short_description' + rec.short_description);
    //1st closed complete create new
    var mediatask = new GlideRecord('sc_task');
    mediatask.initialize();
    mediatask.setValue('request_item', current.getUniqueValue());
   // mediatask.setValue('request_item', '7002c4303b86bad07f9a342a85e45a59');
    mediatask.setValue('short_description', 'Media Recording: ' + rec.short_description);
    mediatask.setValue('assignment_group', rec.assignment_group);
    mediatask.insert();
}
 
Ankita9793_0-1767085870167.png

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@Ankita9793 

you can have sequential catalog tasks in workflow such that 1st is closed, then 2nd is created

why to use script for this?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@Ankita9793 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Dhanraj B
Giga Guru

Hi @Ankita9793 ,

 

If you are building this from scratch, I recommend you to switch to flow designer. There you can use a simple flow logic "Do the following in parallel".

 

something like below:

 

Do the following in parallel:

> Create task 1 (check wait button, so it will wait until task 1 is closed) If task 1 is closed > Create task 4 (add a condition before creating task 4 to check whether the task 1 is closed complete or closed incomplete)

> Create task 2 > Repeat the same steps used for task 1
> Create task 3 > Repeat the same steps used for task 1

 

-Dhanraj.

nayanmule
Kilo Sage

Better choose an approach for going with flow designer. Doing this with scripting would complicate your flow.

Flow designer could easily handle the task creations.

You can add a check for all the three catalog tasks using flow variables.

Then using 'Run in parallel' check which task gets closed first and based on that you can create new tasks.

 

If my response has helped you , kindly mark it as helpful and accept the solution.

Regards,

Nayan