Topic
  • 2 replies
  • Latest Post - ‏2013-12-17T17:12:20Z by JDD23
JDD23
JDD23
8 Posts

Pinned topic Brain Teaser - Field Comparison Script

‏2013-12-16T13:55:45Z |

I have four fields:   Cost,  SchedulePerformance, O verall Status

Each field has four possible values:  (1) Complete,  (2) Major Issues,  (3) Minor Issues, and (4) On Track.

Field value priority, from highest to lowest is:  (2) Major Issues,  (3) Minor Issues,  (4) On Track, and  (1) Complete.

I need a BASIC script that will compare the values in the Cost, Schedule, and Performance fields and place the highest prioity value contanied in the three fields in the Overall Status field.

For example, if the Cost field had a value of (2) Major Issues and the Schedule and Performance fields both had (4) On Track values, the the Overall Status field would reflect (2) Major Issues.

Any help would be much appreciated.

JDD23

  • DonaldN
    DonaldN
    277 Posts
    ACCEPTED ANSWER

    Re: Brain Teaser - Field Comparison Script

    ‏2013-12-16T23:48:12Z  

    Seriously, you just write your own max() function! Since you only have three values to compare, you don't even need to think about some "elegant" solution. Below psudo code should work for you.

    max() {

        if (cost = major or schedule = major or performance = major) {

            return major

        } else if (cost = minor or schedule = minor or performance = minor) {

            return minor

        } else if (cost = ontrack or schedule = ontrack or performance = ontrack) {

            return ontrack

        } esle {

            return complete

        }

    }

    Updated on 2013-12-16T23:49:40Z at 2013-12-16T23:49:40Z by DonaldN
  • DonaldN
    DonaldN
    277 Posts

    Re: Brain Teaser - Field Comparison Script

    ‏2013-12-16T23:48:12Z  

    Seriously, you just write your own max() function! Since you only have three values to compare, you don't even need to think about some "elegant" solution. Below psudo code should work for you.

    max() {

        if (cost = major or schedule = major or performance = major) {

            return major

        } else if (cost = minor or schedule = minor or performance = minor) {

            return minor

        } else if (cost = ontrack or schedule = ontrack or performance = ontrack) {

            return ontrack

        } esle {

            return complete

        }

    }

    Updated on 2013-12-16T23:49:40Z at 2013-12-16T23:49:40Z by DonaldN
  • JDD23
    JDD23
    8 Posts

    Re: Brain Teaser - Field Comparison Script

    ‏2013-12-17T17:12:20Z  

    Thanks DonaldN, appreciate the response--not much of a brain teaser for you! 

    Here's the final script with orginal values converted to colors:

     Dim cost
     Dim schedule
     Dim performance

     cost = GetFieldValue("Status_Task_Cost").GetValue()
     schedule = GetFieldValue("Status_Task_Schedule").GetValue()
        performance = GetFieldValue("Status_Task_Performance").GetValue()

     if cost = "Red" or schedule = "Red" or performance = "Red" then
      SetFieldValue "Status_Task_Overall", "Red"
        else if cost = "Amber" or schedule = "Amber" or performance = "Amber" then
      SetFieldValue "Status_Task_Overall", "Amber"
        else if cost = "Green" or schedule = "Green" or performance = "Green" then
      SetFieldValue "Status_Task_Overall", "Green"
     else SetFieldValue "Status_Task_Overall", "Blue"
     end if
     end if
     end if