• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

86
Vistas
Javascript que muestra valores particulares de múltiples posibilidades

Tengo una lista de proyectos con diferentes estados (Rojo, Amarillo, Verde y Ninguno) Esos están asignados a un programa en particular. Necesito asignar a la variable el color más crítico asignado al programa. Si hay al menos un rojo, necesito mostrar rojo (sin importar si hay otros amarillos o verdes). Si el más crítico es amarillo, necesito mostrar amarillo, sin importar si hay verdes. Si solo hay verdes, necesito mostrar Verde. Si no hay ninguno asignado, necesito mostrar ninguno. El siguiente código está bien para 3 de ellos, no sé cómo agregarle ninguno exactamente. Todos los valores son cadenas.

Saludos 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'; }
almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Ejemplo teórico, ya que no tengo todo el código en cuestión.

 /*** 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 }
almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda