[SOLVED] Calculate using pick list

[SOLVED] Calculate using pick list

Hello,

I am attempting to calculate using three different pick lists and am wondering if there is a better way to do this. The idea is to update a custom field GUDF_LONG3 using the information from GUDF_CHAR41, GUDF_CHAR42 and GUDF_CHAR43 added up together. Each of the pick lists has a value that starts with 0.0, 3.0, 5.0 and 8.0 with one exception being 1.5. These values need to be added together and input into GUDF_LONG3 which I have been able to do, by issues arise if the pick list is changed to a lower or higher value, I am not sure how to get it to recalculate.


  1. var brr=$CS.getText("GUDF_CHAR41");
  2. var tec=$CS.getText("GUDF_CHAR42");
  3. var cos=$CS.getText("GUDF_CHAR43");
  4. var risk1=$CS.getValue("GUDF_LONG3");
  5. var risk2='GUDF_LONG3';

  6. if (brr.startswith("0.0") ||
  7.     tec.startswith("0.0") ||
  8.     cos.startswith("0.0")
  9. ) {
  10.  var risk3,risk4,risk5 = "0";
  11. }

  12.  else if (cos.startswith("1.5")
  13. ) {
  14.  var risk5 = "-1.5";
  15. }

  16.  else if (brr.startswith("3.0") ||
  17.           tec.startswith("3.0") ||
  18.           cos.startswith("3.0")
  19. ) {
  20.  var risk3,risk4,risk5 = "-3";
  21. }

  22.  else if (brr.startswith("5.0") ||
  23.           tec.startswith("5.0") ||
  24.           cos.startswith("5.0")
  25. ) {
  26.  var risk3,risk4,risk5 = "-5";
  27. }

  28.  else if (brr.startswith("8.0") ||
  29.           tec.startswith("8.0") ||
  30.           cos.startswith("8.0")
  31. ) {
  32.  var risk3,risk4,risk5 = "-8";
  33. }

  34. var risk6 = parseInt(risk3, 10) + parseInt(risk4, 10) + parseInt(risk5, 10);
  35. $CS.setValue(risk2,risk6); 

                  New to ADSelfService Plus?