Synchronous call not working from OnSubmit client script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2020 09:47 PM
Hello,
On service portal before submitting a request i am sending one of the field to another third party web using REST call.
Third party will validate and send the response to snow. and if it validates then only i want user to submit the request.
Below is the onSubmit script:
function onSubmit() {
//Type appropriate comment here, and begin script below
var env_name= g_form.getValue('environment_description');
var ga = new GlideAjax('RestCallOss'); -------------- //script include where REST Call logic written
ga.addParam('sysparm_name', 'getResponseMessage');
ga.addParam('sysparm_env_name',env_name);
ga.getXMLWait(ajaxResponse); ------- //Not working
//ga.getXML(ajaxResponse); -------//async call doesn't wait for the response
function ajaxResponse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage(answer);
g_form.setValue('environment_description',"");
}
}
I tried modifying SC catalog item widget and it is working fine there. but it creates lot of dependency further and code will be not modular anymore.
Can anyone help me with how can i achieve this from onSubmit client script?
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2020 10:10 PM
Hi,
Service Portal does not support synchronous GlideAjax. I recommend you take a look at using the client controller to do an HTTP call using one of the REST APIs or scripted REST API.
Kindly go through the following link
https://community.servicenow.com/community?id=community_blog&sys_id=4d6eaeaddbd0dbc01dcaf3231f961964
Please mark correct or helpful based on the impact.
Regards,
Aniket Sawant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2020 10:12 PM
Hi,
For ga.getXMLWait() to work , you also have to use ga.getAnswer() line after that.
Do it and check the response then , however it is not recommended but since you said you need it , then here is the example you can refer
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name','helloWorld');
ga.addParam('sysparm_user_name',"Bob");
ga.getXMLWait();
alert(ga.getAnswer());
NOTE : getXMLWait() doesnt works in Scoped APplication.
Mark my ANSWER as CORRECT and HELPFUL if it works.
ALso refer the below links for getXMLWait() and getXML() if needed
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_GLAX-getXMLWait
https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_GLAX-getXML_S

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2020 09:15 AM
Hello Tushar,
I would suggest use the Rest call script include onChange of the field "env_name" and store the output in a new hidden variable. Then onsubmit client script you can validate the value in the hidden field.
Thanks,
Jagadeesh