Help needed on how to make Priority=critical warning pop-up and reverting other fields back if not

snow_beginner
Mega Guru

Hi,

So the requirement is to make a pop up warning a user when priority changes from high, moderate, low to critical on an incident. This has to be done on change of the field and not on submission.

 

Priority is a read only field and gets automatically calculated based on 'Urgency' and 'Impact' . If both impact=high & urgency=high then priority=critical.

 

I have made a client script for it shown below

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

     if(newValue == 1) 
{
var res= confirm("Warning! Creating an incident with critical priority will automatically start the major incident process. Truly critical incidents are extremely rare so please ensure you fully understand the implications before submitting an incident with that priority. See - critical incident guidance");
  if(res== true){
     return true;
    }
    else{
g_form.setValue('priority',oldValue);
		
        }
     }
}

which is working sort of fine, but here is the issue:

 

Scenario:

impact = high

urgency = low

priority = medium (automatically set based on above values)

 

If I change the following to this:

impact=high

urgency = high

priority = critical (this is working and the pop warning comes up) > If I select 'cancel' on the warning, the priority field will not change (priority=high), however 'urgency' does not change back to low. It stays high and when I save the incident, the warning comes up again (sometimes) > still click cancel > incident gets saved but priority=high.

 

What have I done wrong? How can I make this so that when I click cancel on the warning, the fields of urgency and impact also go back to their old values. I did try to set g_form.setValue('impact', oldValue); in the else statement but that did not work. 

 

Thanks.

 

1 ACCEPTED SOLUTION

Peter Bodelier
Giga Sage

Hi @snow_beginner,

 

You can't change impact with oldvalue, because you only have the oldValue of priority, since that is your trigger of the client script.

 

You could make this work by working with a scratchpad to save the values of impact and urgency when opening the record.

OnDisplay Business Rule:

g_scratchpad.impact = current.impact;
g_scratchpad.urgency = current.urgency;

 

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

     if(newValue == 1) 
{
var res= confirm("Warning! Creating an incident with critical priority will automatically start the major incident process. Truly critical incidents are extremely rare so please ensure you fully understand the implications before submitting an incident with that priority. See - critical incident guidance");
  if(res== true){
     return true;
    }
    else{
g_form.setValue('impact',g_scratchpad.impact);
g_form.setValue('urgency',g_scratchpad.urgency);

        }
     }
}

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

View solution in original post

2 REPLIES 2

Peter Bodelier
Giga Sage

Hi @snow_beginner,

 

You can't change impact with oldvalue, because you only have the oldValue of priority, since that is your trigger of the client script.

 

You could make this work by working with a scratchpad to save the values of impact and urgency when opening the record.

OnDisplay Business Rule:

g_scratchpad.impact = current.impact;
g_scratchpad.urgency = current.urgency;

 

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

     if(newValue == 1) 
{
var res= confirm("Warning! Creating an incident with critical priority will automatically start the major incident process. Truly critical incidents are extremely rare so please ensure you fully understand the implications before submitting an incident with that priority. See - critical incident guidance");
  if(res== true){
     return true;
    }
    else{
g_form.setValue('impact',g_scratchpad.impact);
g_form.setValue('urgency',g_scratchpad.urgency);

        }
     }
}

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Thanks so much! That has solved the issue.