Using synchronous GlideAjax in on submit client script for Service Portal

Ravish Shetty
Tera Guru

hi all,

 

I have a use case to call a script include on submit of a client script and wait for the execution to complete.

 

my understanding is that synchronous GlideAjax does not work when the catalog is opened in Service Portal. How do we go about this?

 

Thanks,

Ravish

6 REPLIES 6

Tony DiRienzo
Giga Guru

Hi Ravish,

You are correct that you cannot use synchronous GlideAjax (getXMLWait()) in the Service Portal. 

However, you can delay form submission until the AJAX response is handled by adding a property to g_form and then programmatically resubmitting the form once the GlideAjax has returned and the answer has been handled.  Then in your onSubmit() script, check for this property and if it is not there, trigger the GlideAjax call and cancel the submit.

Here is some example code that you can update according to your needs:

function onSubmit() {
	if (!g_form.ajaxComplete) {
		ajaxCall();
		return false;
	}
}

function ajaxCall() {
	var ga = new GlideAjax(script_include);
	ga.addParam("sysparm_name", function_name);
	getXMLAnswer(function(a){
		// Do whatever you want to with the answer
		// Once you've handle the answer, run these two lines:
		g_form.ajaxComplete = true;
		g_form.submit();
	});
}

I hope this helps you.

This script works for service portal but not for CMS. Any idea how to make it work in both. I am having a similar requirement.

Allen Andreas
Administrator
Administrator

Hello,

It is not allowed and doing some other loophole isn't recommended either.

If you can explain what you are trying to do, there may be other options that can be done within the form and not needed upon submit. Or...upon submit, a before business rule can do.

Let us know the scenario or...that's about it.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Usually, I would use an onchange client script as a replacement but this needs to be an on submit client script and will be in a variable set that will be tagged to many other catalog items. 

 

This is a tricky issue which we are trying to fix. we have a bunch of catalog items that will now be part of this new order guide. These catalog items were not designed with order guide in mind. So because of this, when we open the order guide and navigate from the first screen, the second screen and finally move to the third summary screen and then if we go back to the second screen by clicking the 'edit options' button, we see the onload client script of the catalog items wipe out the variable values which the user had filled.

 

The ideal thing to do would be to modify these on load client scripts so that this information is retained but that would be a big development change and would involve a bigger regression testing because these catalog items would still be used as standalone items. 

 

So, the workaround we have thought of is to save the information in the user preference table and retrieve it on load. We explored saving the information instead in catalog variables but under certain use cases, the service portal order guide widget wipes out the saved information.