The CreatorCon Call for Content is officially open! Get started here.

help to change the state of a task

Alessa
Mega Guru

Hello dear community, I need help:

 

I have a "special" workflow.
I need that when task 1 (task_id 14) is closed, task 2 (task_id 9)is automatically in state 11 (this is a state that has been made especially for this workflow).

 

For this I have created the following script:

 

(CHANGE STATE 11)

var rec = new GlideRecord('sc_task');

rec.addQuery('request_item', current.sys_id);
rec.addQuery('u_slx_task_id', '9');
rec.query();

if (rec.next()) {
    rec.state = 11;
    rec.update();  
}

 

Please see the attached photo.


However I have not succeeded, when closing task 1 task 2 remains in state in progress (2).

 

Can someone tell me where I am failing or what I could do to achieve that when I close task 1 task 2 remains in state 11?

 

Thanks in advance

 

1 REPLY 1

Tushar
Kilo Sage
Kilo Sage

Hi @Alessa 

 

Is your script is placed on the "Close" activity of Task 1 (task_id 14). This will ensure that the script is executed when Task 1 is closed.The query in your script seems appropriate for identifying Task 2 (task_id 9) associated with the same request item. However, ensure that the request_item and u_slx_task_id values are correctly set.

 

You might want to add additional conditions like checking if Task 2 is in a specific state (e.g., In Progress) before changing it to state 11.

 

 

 

 

var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.request_item); // Assuming 'request_item' is the field name
rec.addQuery('number', '9'); // Assuming 'number' is the field name for task_id
rec.query();

if (rec.next()) {
    if (rec.state != 11) { // Check if Task 2 is not already in state 11
        rec.state = 11;
        rec.update();  
    }
}

 

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar