Set a YES/NO field via script

Alessa
Mega Guru

Hello dear community, I need help:

 

I have a "rather special" workflow (See photo 1).

I need that every time the tasks with id: task.u_slx_task_id = 12 or task.u_slx_task_id = 13 or task.u_slx_task_id = 14 are opened and closed, the field "hubo_contr_cambio" found in task 5 (task.u_slx_task_id = 15) is automatically set to YES.

I have created a variable of type yes/no (u_nvs_ccmfp = true) in the sc_task table, which I have put inside the tasks with id 12, 13 and 14 as a kind of "flag" (See photo 2)

 

My idea was to create a script in task 5 (task.u_slx_task_task_id = 15), which is the one that contains the field "hubo_contr_cambio" so that it can be set to true (See photo 3)

 

However every time I run tests the variable remains at value -none- so nothing really happens (See photo 4)

 

Can someone help me and tell me if my reasoning is right? or maybe I can achieve this in another way?

 

I need that every time the tasks with id 12 or 13 or 14 are opened and closed, the variable "hubo_contr_cambio" is automatically set to "YES" so that another field appears where data can be entered. It should be automatic so that if and only if the flow goes through these tasks this action happens, otherwise (if tasks 12, 13 or 14 are not opened and closed) the field "hubo_contr_cambio" is set to No and the flow follows the path of NO

 

 

 

 

Here the script in task 5 (id 15)

task.u_slx_task_id = 15;
task.u_slx_show_states ='-5,2,3';
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()){
			task.assignment_group = rec.assignment_group;
			task.assigned_to= rec.assigned_to; 
		
		}

if (current.u_slx_task_id == 15) {
    var huboControlCambio = false;

    var taskGR = new GlideRecord('sc_task');
    taskGR.addQuery('u_slx_task_id', 'IN', '13,14,15');
    taskGR.addQuery('u_nvs_ccmfp', true);
    taskGR.query();

    if (taskGR.next()) {
        huboControlCambio = true;
    }

    current.hubo_contr_cambio = huboControlCambio;
}

 

 

 

2 REPLIES 2

Tushar
Kilo Sage
Kilo Sage

Hi @Alessa 

 

can you please try below -

 

if (current.u_slx_task_id == 12 || current.u_slx_task_id == 13 || current.u_slx_task_id == 14) {
    // Check if any of the related tasks have the flag set to true
    var huboControlCambio = false;
    
    var taskGR = new GlideRecord('sc_task');
    taskGR.addQuery('u_slx_task_id IN (12,13,14)');
    taskGR.addQuery('u_nvs_ccmfp=true');
    taskGR.query();

    if (taskGR.hasNext()) {
        huboControlCambio = true;
    }

    current.hubo_contr_cambio = huboControlCambio;
}

 

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

Hello Tushar: Thank you for your help, unfortunately it doesn`t work, the "hubo_contr_cambio" variable is set to -none- As if nothing had been done 😞

 

Alessa_0-1691791865496.png