Calling a Script include from onSubmit Client script does not work?

Yash31
Tera Contributor

I am trying to call a script include from a onSubmit Catalog Client Script. However, it is now working. The Script include is not getting called.

Is there any restriction that Script includes cannot be called from ONSUBMIT client scripts?

Note: Script include is client callable and scope is All Application scope.

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

Hi Yash,

However, it is now working.

If you call a script include on submit, it must be a Synchronous call. Using getXMLWait. Otherwise the Catalog item will be submitted before you get a response from the script include.

For Service Portal getXMLWait is not supported. You can use this alternatively:

getXMLwait alternative for Service Portal

(Please mark the article helpful if it helps you)

 

The Script include is not getting called.

Have you checked the script include is not called? With logs/alerts in the script include?

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Yash,

It should be called but the issue might be by the time the script include function returns something the form get submitted if it is Asynchronous GlideAjax

please share script and what you are trying to achieve

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Willem
Giga Sage
Giga Sage

Hi Yash,

However, it is now working.

If you call a script include on submit, it must be a Synchronous call. Using getXMLWait. Otherwise the Catalog item will be submitted before you get a response from the script include.

For Service Portal getXMLWait is not supported. You can use this alternatively:

getXMLwait alternative for Service Portal

(Please mark the article helpful if it helps you)

 

The Script include is not getting called.

Have you checked the script include is not called? With logs/alerts in the script include?

asifnoor
Kilo Patron

Hi,

There is no such restriction as such. SI can be called from onSubmit client script. But if you are trying to decide the form submission based on the value of SI, then you have to use getXMLWait() so that the form submission waits for the output of SI. Do note that getXMLWait() does not work in Service Portal.

Now coming to SI not being called, try adding logs in the SI and check if its coming or not.

Also go to system logs and check if there is any error in your SI.

Hitoshi Ozawa
Giga Sage
Giga Sage

Script Include is probably getting called. Insert a gs.info() statement in the script include to check if it is getting called.

The problem, however, it that the form is getting submitted before it receives the reply from script include because script include is being called asynchronously.

One option is to call script include using REST API instead of getXML() and then to write a routine to poll for a reply (untested).

Another option is to create a business rule to check the submission or add onChange checks on each field that needs to be checked.