setting alert message when incident priority is changed

ghosh
Kilo Contributor

suppose initially my priority is set and after that i change the priority. After i change the priority,it will display in the worknotes that priority is changed from high to low(if it is changed from high to low) and priority is lowered if priority is changed from high to low

7 REPLIES 7

Since you are indicating you want a prompt, this is accomplished through an onChange Client Script. Set the field name to check to be Priority. Here is a sample that you can use:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


      if (isLoading || newValue == '') {


              return;


      }


      alert('Work notes are required whenever the Priority changes');


      g_form.setMandatory('work_notes', true);


}



If you only want to show the alert when the value increases (e.g.; Priority 2 to Priority 1), you can check the difference between the oldValue and the newValue:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


      if (isLoading || newValue == '') {


              return;


      }


      if (newValue < oldValue) {


              alert('Work notes are required whenever the Priority increases');


              g_form.setMandatory('work_notes', true);


      }


}



Let me know if you have any questions,


Thanks for your response and they both work great. I



My scripting is not that great but would I need another "if" statement to compare old (current) value to new (changed) value and does not require you to enter work notes.



Example: If someone mistakingly changes priority and tries to submit and realizes they didn't want to change priorities after all and changes priority back to its original value they would still be required to enter work notes. I may be just as simple to enter work notes but was just wondering.



Thank you again


You could just add an else condition that makes the field to not be mandatory. That way if the value is the same or is lower, then worknotes will not be required:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


      if (isLoading || newValue == '') {


              return;


      }


      if (newValue < oldValue) {


              alert('Work notes are required whenever the Priority increases');


              g_form.setMandatory('work_notes', true);


      } else {


              g_form.setMandatory('work_notes', false);


      }


}



Let me know if this is helpful,