How to deal with callback function?

Yogesh Raut
Tera Contributor
var redirect_msg = getMessage('redirect_popup', function(msg) {});

if (confirm(redirect_msg) == true) { 
top.window.open('some link to redirect'); 
return true; 
} else { 
return false; 
}

In the above line of code, onSubmit of client script, confirm method is printing 'redirect_popup' in the popup message in the first attempt.

Until then, in the second attempt, getMessage gets value of 'redirect_popup' and prints the same in the confirm method.

How can I deal with getMessage so that I can get the message in first attempt.

1 ACCEPTED SOLUTION

Tom Sienkiewicz
Mega Sage

try the below:

 

function onSubmit() {
if (g_scratchpad.isFormValid){
	return true;
}
var actionName = g_form.getActionName();

var redirect_msg = getMessage('redirect_popup', function(msg) {
if (confirm(msg) == true) { 
top.window.open('some link to redirect');
g_scratchpad.isFormValid = true; 
g_form.submit(actionName);
} else { 
return false; 
}
});
return false;

}

it may not work as I have not tested it, but this should be the general idea: first you execute the callback function and immediately after that stop saving the form, then when the callback executes, if user confirms, you trigger saving of the form again, if the user declines, basically do nothing.

 

View solution in original post

2 REPLIES 2

Tom Sienkiewicz
Mega Sage

try the below:

 

function onSubmit() {
if (g_scratchpad.isFormValid){
	return true;
}
var actionName = g_form.getActionName();

var redirect_msg = getMessage('redirect_popup', function(msg) {
if (confirm(msg) == true) { 
top.window.open('some link to redirect');
g_scratchpad.isFormValid = true; 
g_form.submit(actionName);
} else { 
return false; 
}
});
return false;

}

it may not work as I have not tested it, but this should be the general idea: first you execute the callback function and immediately after that stop saving the form, then when the callback executes, if user confirms, you trigger saving of the form again, if the user declines, basically do nothing.

 

Hi @Tomasz Sienkiewicz

I have tested the solution and its working fine. 

Thank You.