How to trigger a notification using gs.eventQueueScheduled based on a RITM state change

Prueba
Tera Contributor

It is required that when a rhythm is changed to the “waiting” state and 5 business days pass and the status is not updated, the system automatically changes the rhythm to the closed or completed state.

1.

// Business Rule: Trigger Auto-Close on "On Hold" (-5) after 10 minutes
(function executeRule(current, previous /*null when async*/) {
if (current.state == '-5' && previous.state != '-5') {
var tenMinutesLater = new GlideDateTime();
tenMinutesLater.addseconds(10); 

// Programar el evento que cerrará automáticamente el requerimiento
gs.eventQueueScheduled('close_on_hold_request', current, '', '', tenMinutesLater);
}
})(current, previous);

 

2. create event

Prueba_0-1723772997002.png

3 create script action

// Script Action: Close request after 1 minute
(function process(event) {
    // Obtén el GlideRecord del evento
    var gr = new GlideRecord('sc_req_item');
    if (gr.get(event.getValue('sys_id'))) { // Asegúrate de que el registro existe
        if (gr.state == '-5') { // Verifica que el estado sea "En espera" (-5)
            gr.state = '3'; // Cambia el estado a "Cerrado" (valor 3 para "Closed", ajusta si es necesario)
            gr.update();
        }
    }
})(event);
 

Prueba_1-1723773063050.png

 

I don't know what I'm doing wrong but it doesn't work

 

4 REPLIES 4

Prueba
Tera Contributor

It's 5 days but I'm doing it with 10 seconds to do the test.

and the business rule is executed after the status changes to "on hold"

 

Prueba
Tera Contributor

It is important to say that it does execute the event and what is failing is the action script

Prueba_0-1723775607300.png

 

 

Community Alums
Not applicable

Hi @Prueba, I tried your problem in my PDI, please make changes in Business Rule 

Add event like below line 

gs.eventQueue('close_on_hold_request',current,current.number,tenMinutesLater);
You are passing an extra parameter here. 
 
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak

 

Hello @Sarthak I made the change in the business rule but it does not make the change and "gs.eventQueueScheduled" must be used so that it is scheduled and executed 10 seconds later