Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
Javascript displaying particular values from multiple possibilities

I have a list of projects with different statuses ( Red, Yellow, Green and None) Those ones are assigned to particular program. I need to assign to the variable the most critical colour assigned to the program. If there is at least one red I need to display red( no matter if there are other yellows or greens) If the most critical one is yellow I need to display Yellow, not matter if there are greens. If there are only greens I need to display Green. If there is none assigned I need to display none. Below code is OK for 3 of them, I do not know how to exactly add None to it. All values are strings.

Regards Piotr

function getProjectStatusProgram(program){
var status = '';
var grPrgTask = new GlideRecord('project');
grPrgTask.addQuery('u_program', program);
grPrgTask.query();
while (grPrgTask.next()){
    if (grPrgTask.overall_health == 'red'){
        status = "red";
        break;
    } else if (grPrgTask.overall_health == 'yellow'){
        status = 'yellow';          
    }           
}
if(status =='red' || status =='yellow')
return status;
else
return 'green';

}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Theoretical example, since I do not have all the code in question.

/***
Returns a string with following task status priority:
 1: "red": if atleast one task has status "red"
 2: "yellow": if atleast one task has status "yellow"
 3: "none": if atleast one task has status "none"
 4: "green": if no task has either status "red", "yellow" or "none"
**/
function getProjectStatusProgram(program){
    //REM: Set default status to "green" due to "If there are only greens I need to display Green"
    var status = 'green';

    var grPrgTask = new GlideRecord('project');
    grPrgTask.addQuery('u_program', program);
    grPrgTask.query();

    while(grPrgTask.next()){
        //REM: "If there is at least one red I need to display red( no matter if there are other yellows or greens)"
        if(grPrgTask.overall_health == 'red'){
            status = "red";
            break;
        };

        //REM: "If the most critical one is yellow I need to display Yellow, not matter if there are greens."
        if(grPrgTask.overall_health == 'yellow'){
            status = 'yellow'
        }
        //REM: If current status is still "green" and this tasks status is "none" -> "none"
        //REM: Since it is only "green" if all are "green"
        else if(status == 'green' && grPrgTask.overall_health == 'none'){
            status = 'none'
        }
    };

    //REM: Just return the status
    return status
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda