Reverting field value to previous value in client script

Khalnayak
Tera Guru

Hi,

I have a client script, see below.

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

	// if incident already poposed MI then do not run script
	if(g_form.getValue('major_incident_state') == 'proposed'){


 return false;
}

else {

// Trigger script

}
     var priority = g_form.getValue('priority'); 
    if (priority == 1 || priority == 2) {
		
		// This prevents the form from checking if any mandatory fields need filling if the form values change
	g_form.checkMandatory = false; 
		
		// This prompts the alert box
   var response = confirm('Priority 1 & 2 tickets follow the major incident process. Please confirm that you would like to propose this ticket as a Major Incident.');

// If cancel is pressed or the dialog is closed the response is empty	
   if (response == true){
 
    gsftSubmit(null, g_form.getFormElement(), 'sysverb_mim_propose'); //MUST call the 'Action name' set in this UI Action

   } else {
       g_form.setValue('impact', oldValue);
       g_form.setValue('urgency', oldValue);
       g_form.setValue('priority', oldValue);
   return false; 
   }
   }
}

 

If you look at the last else bracket, I want the fields to revert back to their old value, but using oldvalue function reverts all the fields back to the priority field where the onchange client script is pointing to.

1. So i want impact and urgency to revert back to their previous value.

2. If it is a new incident and there is no previous value for all three fields, I want the fields to be set to value 4.

How can I achieve the above please?

8 REPLIES 8

so the new record bit works.

however, if it is existing record, it is and if i click cancel, it reverts the priority back to previous value but not urgency and impact.

im using below code

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '' || oldValue == 1 || oldValue == 2) {
      return;
   }
	// gets value of impact and urgency and stores it as old
	var impact_old = g_form.getValue('impact');
	var urgency_old = g_form.getValue('urgency');

	// if incident already poposed MI then do not run script
	if(g_form.getValue('major_incident_state') == 'proposed'){


 return false;
}

else {

// Trigger script

}
     var priority = g_form.getValue('priority'); 
    if (priority == 1 || priority == 2) {
		
		// This prevents the form from checking if any mandatory fields need filling if the form values change
	g_form.checkMandatory = false; 
		
		// This prompts the alert box
   var response = confirm('Priority 1 & 2 tickets follow the major incident process. Please confirm that you would like to propose this ticket as a Major Incident.');

// If cancel is pressed or the dialog is closed the response is empty	
   if (response == true){
 
    gsftSubmit(null, g_form.getFormElement(), 'sysverb_mim_propose'); //MUST call the 'Action name' set in this UI Action

   } else {
	if (g_form.isNewRecord()) {
   impact_old  = 4;
	urgency_old = 4;
	priority = 4;
		
 }
      g_form.setValue('impact', impact_old);
		g_form.setValue('urgency', urgency_old);
       g_form.setValue('priority', oldValue);
 
   return false; 
     
   }
   }
}

 

so the use case is only for 1 and 2, as if user selects priority as p1 or p2,  the alert box and UI action is triggered.

if the user clicks cancel, it should revert values to old values for existing incidents and to value 4 for new record

@Manisha Kumari @Manisha Kumari  please advise

@Harshvardhan are you able to help here please? this is the same client script we talked about yesterday. 

@Ankur Bawiskar  can you advise here please