Validation script for impact and urgency field when 'promote to major incident' ui button is clicked

Constance1
Tera Contributor

Hi 

 

I have a requirement when ' promote to major incident' button is clicked, a message should pop up to indicate the user to adjust the priority field to be critical or high when the priority is not in critical or high, so users are mandated to re-enter/populate the values again for 'impact' and 'urgency' fields. 

 

I have created an onSubmit client script and modified the 'promote to major incident' ui script to the following but somehow when incident is successfully promoted, the 'major incident state' sticks to 'proposed' instead of 'accepted' . Can someone please point out why is my client script overwriting the major incident trigger rules?

 

onSubmit client script:

function onSubmit() {
if (g_scratchpad.makeMandatory) {
var impact = g_form.getValue('impact');
var urgency = g_form.getValue('urgency');
var priority = g_form.getValue('priority');

if (priority == '1' && priority == '2') {
g_form.setMandatory(impact, false);
g_form.setMandatory(urgency, false);
return true;
}

else if (impact == '' || urgency == '') {
alert('Please fill in both Impact and Urgency fields to reflect Priority is Critical or High before submitting the form.');
return false;
}

g_form.setMandatory(impact, true);
g_form.setMandatory(urgency, true);
return true;
}
}
1 REPLY 1

Gurpreet07
Mega Sage

Hi, I am not sure what you are trying to do here but there's an error in your script, below condition will never be evaluated to true bz priority can either be 1 or 2 but can't be both at same time.  Or maybe you want to use an Or (||) operator instead.

 

if (priority == '1' && priority == '2') {
g_form.setMandatory(impact, false);
g_form.setMandatory(urgency, false);
return true;
}
 
Usually if we need to put some validation before a Server side (Not client) Ui action is clicked then we can do that by assigning an action name to the ui action and then configure an on submit client script and check if that ui action is clicked.
 
if(g_form.getActionName() =='promote_to_major_incident'){     //if    promote_to_major_incident  is the action name  
//Validate here
}