Custom Status Bar

epuchals
Kilo Contributor

Is there a way to add a field type similar to Percent Complete but without referencing percentage? When we add new projects, we go through a scoring process that generates a number from zero to 100 representing the potential impact of the project and the probability that the project will be completed successfully--the higher the score, the more likely the project will be considered for implementation. I'd like to represent this score as a colored bar similar to Percent Complete but without any reference to percentages.

Any ideas?

Thanks in advance,

  Eric...

1 ACCEPTED SOLUTION

derycklio
Mega Expert

Hi Eric,



If you love every default behavior of Percentage Complete field, except it shows the % character in the list view, the quickest solution is probably just to drop the % character via a UI Script.


Screen Shot 2015-09-15 at 11.50.01 pm.png



/**


* UI Script


*


* Name: CustomizePercentageCompleteCellView


* Application: Global


* Global: True


* Active: True


*/




document.observe('dom:loaded', function() {


  // Says incident.u_score is the Percentage Complete field, but I don't like the % suffix when it's displayed in the list view.




  var headers = document.getElementsByTagName("thead")[0].childNodes[0].childNodes;




  // Find out the Cell Index of incident.u_score from the table header, so I don't have to hardcode the index in script.


  var u_score_cell_index = false;


  for (var i = 0; i < headers.length; i++) {


  if ("incident.u_score" == headers[i].getAttribute("glide_field")) {


  u_score_cell_index = i;


  break;


  }


  }


  if (false == u_score_cell_index) {


  return;


  }




  var all_percentage_complete_fields = document.getElementsByClassName("percent_complete_text");


  for (var i = 0; i < all_percentage_complete_fields.length; i++) {


  // If this Percentage Complete field is incident.u_score


  if (u_score_cell_index == all_percentage_complete_fields[i].parentNode.parentNode.cellIndex) {


  // Remove the % sign


  all_percentage_complete_fields[i].innerHTML = all_percentage_complete_fields[i].innerHTML.replace('%', '');


  }


  }


});



Or ServiceNowScripts/UI Script.js at master · dereklio/ServiceNowScripts · GitHub if you want to see the codes with better indentation.


View solution in original post

6 REPLIES 6

Because we didn't modify any existing behavior of the Percentage Complete field, I believe you can still follow the section 3 and 4 of this Wiki page http://wiki.servicenow.com/index.php?title=Creating_a_Percent_Complete_Field#gsc.tab=0 to configure the color of the bar. Normally, I would suggest using as many standard features of ServiceNow to maximize forward compatibility.



However, if the default behavior does not fit, you still have the score in all_percentage_complete_fields[i].innerHTML anyway. You should be able to adjust the background color of the bar via CSS, let me know if you need to go this route and run into any issue. I can mesh up some quick codes for you later today.


Deryck:



Using standard features is good advice and something we generally follow. I don't want to get too far off the beaten path here so I'll probably stick with the original mod you suggested and if I can't get the colors to change then so be it.



Thanks a ton for the help,


  Eric...