onChange script error: ReferenceError: callback is not defined function

Khalnayak
Tera Guru

Hi,

I am getting the below error when my onchange client script is executed.

The script is still working fine but get this error when it does.

The script basically prompts to propose incident as MI when priority is 1 or 2.

 

find_real_file.png

 

This is my script:

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; 
		
		

// If cancel is pressed or the dialog is closed the response is empty	

var confirm = new GlideModal('glide_modal_confirm', true, 300);
	confirm.setTitle(new GwtMessage().getMessage('Propose as MI confirmation'));
	confirm.setPreference('body', new GwtMessage().format("Priority 1 & 2 tickets follow the major incident process. Please confirm that you would like to propose this ticket as a Major Incident."));
	confirm.setPreference('focusTrap', true);
	confirm.setPreference('onPromptComplete', doComplete);
	confirm.setPreference('onPromptCancel', doCancel);
	confirm.render();
	
	function doComplete() {
			var dialog = new GlideModal('sn_major_inc_mgmt_mim_propose', false, 651, 250);
	getMessage('Propose Major Incident', function(msg) {
		dialog.setTitle(msg);
	});
	ScriptLoader.getScripts('/scripts/incident/glide_modal_accessibility.js', function() {
		dialog.template = glideModalTemplate;
		dialog.on('bodyrendered', function(event) {
			glideModalKeyDownHandler(event, dialog.getID());
		});
		dialog.setPreference('WORK_NOTES', g_form.getValue('work_notes'));
		dialog.setPreference('BUSINESS_IMPACT', g_form.getValue('business_impact'));
		dialog.setPreference("focusTrap", true);
		dialog.render();
	});

}
		callback(true);
	
	
	function doCancel() {
g_form.setValue('impact', 4);
	g_form.setValue('urgency', 4);
	priority = 4;
		callback(false);
		
	}
	}
   
 }
  
1 ACCEPTED SOLUTION

Khalnayak
Tera Guru

Hi, so the error was because the callback(true) was outside the curly bracket above it, it should have been inside it, so put it inside and that fixed it.

View solution in original post

2 REPLIES 2

Naveen Velagapu
Mega Guru

hi @Khalnayak ,

It seems to me that "callback(true);" function is not defined. Can you please comment "callback(true); & callback(false);" and try ?

 

Mark "correct answer / Helpful" if this is useful.

Khalnayak
Tera Guru

Hi, so the error was because the callback(true) was outside the curly bracket above it, it should have been inside it, so put it inside and that fixed it.