Why would an (onchange) client script pop-up run multiple times upon 'Save/Update' of record?

coreyo
Giga Contributor

I have an 'onChange' on the priority field, client script.  When the priority is changed (record not yet saved) pops up as expected.  When the user goes to 'Save / Update' the record, the pop up fires multiple times.  This is not an onSubmit, so not understanding why?  script below.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (oldValue != newValue) {
   //Popup asking user to validate the priority change
	   if(!g_form.isNewRecord()){
	   alert('You are changing the priority from ' + 'P' + oldValue + ' to ' + 'P' + newValue + '.  Please indicate in additional comments why the priority was changed and who approved.');
   }
}
}
1 ACCEPTED SOLUTION

That script works perfectly fine in my dev instance. Only fires on Priority change, never onLoad, or onSubmit. Are you sure the Priority change is being written to the dbase and something else isn't going on?

View solution in original post

16 REPLIES 16

I agree has to be, but I don't know what.  This is only popup being used in this case.  It's like my save/update function is recalculating the priority thus thinking it is "changed" again.  I'm just not finding it.

What if we change the script a bit like this:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || g_form.isNewRecord()) {
		return;
	}
	
	if (oldValue != newValue) {
		//Popup asking user to validate the priority change
		alert('You are changing the priority from ' + 'P' + oldValue + ' to ' + 'P' + newValue + '. Please indicate in additional comments why the priority was changed and who approved.');
	}
}

I think that did it, gave it multiple attempts and only firing onchange only, no longer during save!  Awesome.  Thank you very much.

I am finding these multiple erroneous alerts occur only if a change is made on both fields.  I have two onchange client scripts, 1 for an onchange on my Priority field and another onchange client script for the Assignment group field.

The multiple alerts only occur if both priority is changed and then assignment group once the changes are saved/updated.

If individually updated, it does not loop.  Just 1 alert message.

Any suggestion is appreciated.

 

You have 2 onChange Client scripts both with alert that will generate a pop-up. If you change one field, you get one pop-up. Then change another field, another pop-up.

What are you trying to have happen?