How to use synchronous call on service portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2017 06:47 AM
Hi Team,
I want to do date validation. Here getXMLWait() is not working on service portal. Any other alternative solution for this. Because i can not use asynchronous glide ajax, it will not wait for the service response. I am keeping my code below. I am sure that my script include is working good.
function onSubmit() {
var startDate = g_form.getValue("start");
var endDate = g_form.getValue("end");
if(startDate != undefined && startDate != '' && endDate != undefined && endDate != ''){
var validation = new GlideAjax('OLA_DongleDateValidation');
validation.addParam('sysparm_name','ola_Startvalidation');
validation.addParam('sysparm_Start',startDate );
validation.addParam('sysparm_End',endDate );
//validation.getXMLWait(); not working in portal
//var answer = validation.getAnswer();
validation.getXML(HelloWorldParse);
var valid = new GlideAjax('OLA_DongleDateValidation');
valid.addParam('sysparm_name','ola_currentdatevalidation');
valid.addParam('sysparm_Start',startDate);
valid.addParam('sysparm_End',endDate );
valid.getXMLWait();
var answer1 = valid.getAnswer();
alert(answer1);
valid.getXML(HelloWorld);
}
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer = false){
alert("End date should not be before start date");
return answer;
}
}
function HelloWorld(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer = false)
{
alert("Start date should not be a past date");
return answer;
}
}
synchronous
- Labels:
-
Service Catalog
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2017 07:19 AM
Hi Bosco
I would suggest to have a look to this documentation
documentation/client_scripting.md at master · service-portal/documentation · GitHub
Maybe you can find some more information about what it is allowed.
Cheers
R0b0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2017 07:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2019 06:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2017 07:42 AM
The getXMLWait() function is not supported in scoped applications nor Service Portal. Also, async calls are not possible in onChange scripts because the script runs to completion without waiting on the return. I would recommend moving client validation to onChange scripts.
Client Script Best Practices - ServiceNow Wiki
Other way is to find a client side alternative to evaluate dates instead of relying on server side APIs.
Date Format Validation in the new Service Portal