Color code item current states

I have the following code that works but i would like to add an additional property so it too receives the same color coding that the new_state property receives. I am not familiar with C# coding so I would appreciate someone's help with this.

i want to add the property "affected_state" so that both properties "new_state" and "affected_state" get the color coding in the coding below:

for (int i=0; i < this.getItemCount(); i++){

  string bg_color;

  string myCss;

  string text_color = "#000000";

  Item thisItem = this.getItemByIndex(i);

  string thisStatus = thisItem.getProperty("new_state","");

    //------

      switch (thisStatus){

          case "Preliminary":

          case "In Review":
          
          bg_color = "#FFCC00"; // yellow

          text_color = "#000000";  // black

          break;

          case "In Change":
          
          case "Inactive":

          bg_color = "#80EE80"; // light green

          text_color = "#000000";  // black

          break;
          
          case "Released":

          bg_color = "#55CC55";  // green

          text_color = "#000000";  // black

          break;

          case "Superseded":

          case "Obsolete":

          bg_color = "#FF8888";  // light red

          text_color = "#000000";  // black

          break;

          default:

          bg_color = ""; // none

          break;

      }

 

  if (bg_color != "" ){

     myCss = ".new_state { background-color: " + bg_color + "; color: " + text_color + "; }";

    thisItem.setProperty("css",myCss);

  }

}

return this;

Parents
  • Hi Dkinsley

    Try this code and let me know if it works

    string bg_color_new = "";
    string myCss_new = "";
    string text_color_new = "#000000";
    string bg_color_aff = "";
    string myCss_aff = "";
    string text_color_aff = "#000000";
    for (int i = 0; i < this.getItemCount(); i++)
    {
    Item thisItem = this.getItemByIndex(i);
    string thisStatus = thisItem.getProperty("new_state", "");
    string thisAffStatus = thisItem.getProperty("affected_state", "");
    switch (thisStatus)
    {
    case "Preliminary":
    case "In Review":

    bg_color_new = "#FFCC00"; // yellow
    text_color_new = "#000000"; // black
    break;
    case "In Change":

    case "Inactive":
    bg_color_new = "#80EE80"; // light green
    text_color_new = "#000000"; // black
    break;

    case "Released":
    bg_color_new = "#55CC55"; // green
    text_color_new = "#000000"; // black
    break;
    case "Superseded":
    case "Obsolete":
    bg_color_new = "#FF8888"; // light red
    text_color_new = "#000000"; // black
    break;
    default:
    bg_color_new = ""; // none
    break;
    }
    switch (thisAffStatus)
    {
    case "Preliminary":
    case "In Review":

    bg_color_aff = "#FFCC00"; // yellow
    text_color_aff = "#000000"; // black
    break;
    case "In Change":

    case "Inactive":
    bg_color_aff = "#80EE80"; // light green
    text_color_aff = "#000000"; // black
    break;

    case "Released":
    bg_color_aff = "#55CC55"; // green
    text_color_aff = "#000000"; // black
    break;
    case "Superseded":
    case "Obsolete":
    bg_color_aff = "#FF8888"; // light red
    text_color_aff = "#000000"; // black
    break;
    default:
    bg_color_aff = ""; // none
    break;
    }

    if (bg_color_new != "")
    {
    myCss_new = ".new_state { background-color: " + bg_color_new + "; color: " + text_color_new + "; }";
    }
    if (bg_color_aff != "")
    {
    myCss_aff = ".affected_state { background-color: " + bg_color_aff + "; color: " + text_color_aff + "; }";
    }
    thisItem.setProperty("css", myCss_new + " " + myCss_aff);
    }
    return this;

    Thanks

    Gopikrishnan R

  • Hi Gopikrishnan,

    Your scrip colors the new_state but not the affected_state. Nothing has to be added to the lines below?

    if (bg_color != "") {
    myCss = ".new_state { background-color: " + bg_color + "; color: " + text_color + "; }";
    thisItem.setProperty("css", myCss);
    }

Reply Children