Validate the approver for a Request Item

Harold Hoyos
Tera Contributor

I'm triying this script in a bussines rule to valide if a request Item has an exactly approver: 

 

 

(function executeRule(current, previous /*null when async*/) {

    // Obtener el sys_id del registro actual
    var currentRecordId = current.sys_id;
    // sys_id del aprobador que deseas validar
    var approverSysId = '6242245c47a221906785eb62e36d432e'; // Reemplaza esto con el sys_id específico

    // Crear una instancia de GlideRecord para la tabla 'sysapproval_approver'
    var gr = new GlideRecord('sysapproval_approver');
    gr.addQuery('sysapproval', currentRecordId); // Buscar registros que correspondan al sys_id del registro actual
    gr.addQuery('approver', approverSysId); // Buscar registros que correspondan al sys_id del aprobador específico
    gr.query();

    // Comprobar si hay algún registro que coincida
    if (gr.next()) {
       gs.addErrorMessage("El elemento de solicitud debe tener al menos dos aprobadores antes de poder ser actualizado.");
       // current.setAbortAction(true); // Evitar la actualización del registro
    } 

})(current, previous);

 

 

But it's not working, this should show a message if the request item has the approver that I put in the script, it's clear?

2 REPLIES 2

Murthy Ch
Giga Sage

Hi @Harold Hoyos 

I'm not clear with your requirement. Can you please elaborate more what exactly do you want to achieve?

 

Thanks,
Murthy

I want to show a notice when the request item has the approver "Karla" and the resolutor want to change the state, the notice should be show to the user and say "Please add another approver", in the bussines rule script I try it, but it is not working