Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!