How can I capture the number of a task that was created at the same time as a workflow triggered?

Reinaldo Vieira
Tera Contributor

Good morning, everyone.

 

I am developing a workflow that works with the triggering of Catalog Tasks after an approval in RITM. It is necessary that the requester receives a message that the SCTASK was created right after the approval, and that this message carries the task number (SCTASKXXXXX).

 

How can i do this? I'm trying but the task number at the message is undefined

 

ReinaldoVieira_0-1735915964037.png

 

workflow.scratchpad.task_number = task.number;

var grTask = new GlideRecord('sc_task');
grTask.addEncodedQuery('active=true^request_item=' + current.getValue('sys_id'));
grTask.addEncodedQuery('number=' + workflow.scratchpad.task_number);
grTask.orderBy('sys_updated_on');
grTask.setLimit(1);
grTask.query();

while (grTask.next()) {
    var tarefa = grTask.number.getValue();
}

Here is the script I've used inside the task activity

1 ACCEPTED SOLUTION

Ahmmed Ali
Mega Sage

Hello @Reinaldo Vieira 

 

In your screenshot you do not have approval activity, but task activity right after begin. even in this case or if there is approval before task, you can have two transitions from approval/begin(in screenshot), one directly to task creation, then second one add 5-10 seconds delay, then after delay configure an event trigger. in the event trigger activity, for parameter 1 you can write script as below to get SCTASK (for the current RITM last created SCTASK) and pass number. Now configure the notification on the event and task number can be read from event.

 

var grTask = new GlideRecord('sc_task');
grTask.addEncodedQuery('active=true^request_item=' + current.getValue('sys_id'));
grTask.orderByDesc('sys_updated_on');
grTask.setLimit(1);
grTask.query();
if (grTask.next()) {
    return grTask.number.toString();
}

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

1 REPLY 1

Ahmmed Ali
Mega Sage

Hello @Reinaldo Vieira 

 

In your screenshot you do not have approval activity, but task activity right after begin. even in this case or if there is approval before task, you can have two transitions from approval/begin(in screenshot), one directly to task creation, then second one add 5-10 seconds delay, then after delay configure an event trigger. in the event trigger activity, for parameter 1 you can write script as below to get SCTASK (for the current RITM last created SCTASK) and pass number. Now configure the notification on the event and task number can be read from event.

 

var grTask = new GlideRecord('sc_task');
grTask.addEncodedQuery('active=true^request_item=' + current.getValue('sys_id'));
grTask.orderByDesc('sys_updated_on');
grTask.setLimit(1);
grTask.query();
if (grTask.next()) {
    return grTask.number.toString();
}

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali