Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Assigning a task to a previous task fulfiller

Mario25
Giga Expert

Hello,

I have a workflow that opens a first task for approval then a series of tasks.  I require the second catalog task to be assigned to the assignee of the first.  I`ve tried a few things but the task keeps opening for the proper group but the assigned to is empty.

Workflow:

find_real_file.png

Script in the catalog task that is trying to assign to the tech:

find_real_file.png

 

Please help, we will be using this same workflow many times over.

1 ACCEPTED SOLUTION

Mario25
Giga Expert

I finally realized that the approval task is the one opening the next task so I added this to the approval task to pull the scratchpad and push it into the next task:

 

var grTask = new GlideRecord("sc_task");
grTask.addQuery("sys_id", workflow.scratchpad.TaskId);
grTask.query();

while (grTask.next()) {
    grTask.assigned_to = tsk.assigned_to.sys_id;
    grTask.update();
}

View solution in original post

3 REPLIES 3

timmyweytjens
Kilo Guru

Hello Mario,

 

Since assignment_group is a reference field, you should either do addQuery("assignment_group.name", "EXP - Techniciens"); or add in the sys_id of the assingment group.

However a better solution would be to add in the first task (the Stella Access Approval) a line to add it to the workflow scratchpad:

workflow.scratchpad.stellaTaskId = task.setNewGuid(); // get the sys_id of this task on the workflow scratchpad

Then you could do in this task:

var grTask = new GlideRecord("sc_task");

if(grTask.get(workflow.scratchpad.stellaTaskId)){

  task.assigned_to = grTask.assigned_to;

}

This would work even if the user changes the short description or assignment group.

I just modified the first task to add that to the scratchpad and added the script into that task and same result.

find_real_file.png

Mario25
Giga Expert

I finally realized that the approval task is the one opening the next task so I added this to the approval task to pull the scratchpad and push it into the next task:

 

var grTask = new GlideRecord("sc_task");
grTask.addQuery("sys_id", workflow.scratchpad.TaskId);
grTask.query();

while (grTask.next()) {
    grTask.assigned_to = tsk.assigned_to.sys_id;
    grTask.update();
}