How validate the number of approvers for a request and the state
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2024 04:04 PM
I'm trying validate the number of approvers of a request, and I'm ussing a client script:
function onSubmit() {
// Obtener el ID del registro actual
var currentRecordId = g_form.getUniqueValue();
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', currentRecordId);
gr.query();
var estado = g_form.getValue('state');
var approverCount = 0;
// Contar el número de aprobadores asociados con el registro actual
while (gr.next()) {
approverCount++;
}
// Si el número de aprobadores es menor que 2, mostrar un mensaje de error y evitar la actualización
if (approverCount < 2) {
alert("El elemento de solicitud debe tener al menos dos aprobadores antes de poder ser actualizado.");
return false; // Evitar la actualización del registro
}
return true; // Permitir la actualización del registro
}
That's fine, valide the number of approvers and show a alert if it is not 2, but I wanna add the funtion that only it work when the state is open and after the request has been created.
It's clear?
1 REPLY 1

Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 01:11 AM
Hi @Harold Hoyos ,
Try using below script -
function onSubmit() {
var currentRecordId = g_form.getUniqueValue();
var estado = g_form.getValue('state');
// Check if the state is "open" and the record has already been created
if (estado === 'open' && currentRecordId) {
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', currentRecordId);
gr.query();
var approverCount = 0;
while (gr.next()) {
approverCount++;
}
if (approverCount < 2) {
alert("El elemento de solicitud debe tener al menos dos aprobadores antes de poder ser actualizado.");
return false;
}
}
return true;
}
Please mark as Accepted Solution if this solves your query .