confirm change of a field keep looping on cancel

ServNowDev
Tera Guru

I want to have an onchange client script that when the category field is changed it confirms that the field is changed, if the user doesnt want to change then it goes back to the previous category, for some reason when i select cancel it sends me into a loop of asking for the confirm message over and over. 

 

 

var confirmChange = confirm('Are you sure you want to change the Category?');
    if (confirmChange) {
        g_form.save();
    } else {
        g_form.setValue('u_category', oldValue);
		
    }

 

1 ACCEPTED SOLUTION

I don't see any update. but I tried your client change on the incident table 'category' field. And came up with the following for the client script:

 

 

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

   if (oldValue == newValue) {
      return;
   }

   var confirmChange = confirm('Are you sure you want to change the Category?');
    if (confirmChange) {
        g_form.save();
    } else {
        g_form.setValue('u_category', oldValue);
    }
   
}

 

I added a check to  prevent the loop. Lines 6 - 8.

View solution in original post

3 REPLIES 3

Bert_c1
Kilo Patron

You should post more context. I'm sure someone here can assist.

updated

 

I don't see any update. but I tried your client change on the incident table 'category' field. And came up with the following for the client script:

 

 

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

   if (oldValue == newValue) {
      return;
   }

   var confirmChange = confirm('Are you sure you want to change the Category?');
    if (confirmChange) {
        g_form.save();
    } else {
        g_form.setValue('u_category', oldValue);
    }
   
}

 

I added a check to  prevent the loop. Lines 6 - 8.