top of page

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

Understanding getXML() and getXMLWait() in ServiceNow

Updated: Mar 29

In ServiceNow development, GlideAjax is commonly used to fetch server-side data within client-side scripts without reloading the page. Two crucial methods provided by GlideAjax are getXML() and getXMLWait(). Understanding their differences and proper usage is essential for developing efficient and responsive applications.


getXML() - Asynchronous Server Calls


The getXML() method makes asynchronous calls to the server. This means the client-side script continues execution immediately after sending the request without waiting for the server response. Asynchronous calls enhance the user experience by keeping the UI responsive and interactive.


Use getXML() in scenarios such as populating form fields dynamically, retrieving reference information, or performing calculations without halting user interaction.


Example of using getXML():

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') return;

    var ga = new GlideAjax('UserInfoAjax');
    ga.addParam('sysparm_name', 'getUserPhone');
    ga.addParam('sysparm_user_id', newValue);
    ga.getXML(function(response) {
        var phoneNumber = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('caller_phone', phoneNumber);
    });
}

getXMLWait() - Synchronous Server Calls


Unlike getXML(), getXMLWait() performs a synchronous call, meaning the client script pauses and waits until the server responds. This method should be limited to critical operations where immediate server validation is necessary, as it can make the UI unresponsive.


Use getXMLWait() when immediate validation or conditional checks are critical, for example, verifying permissions or conditions before form submission.


Example of using getXMLWait():

function onSubmit() {
    var ga = new GlideAjax('UserValidator');
    ga.addParam('sysparm_name', 'validateUser');
    ga.getXMLWait();

    var result = ga.getAnswer();
    if (result !== 'true') {
        g_form.addErrorMessage("You are not authorized to submit this form.");
        return false; // Stops submission if validation fails
    }
    return true;
}

Troubleshooting Tips


  • Ensure your Script Include is set to "Client callable."

  • Double-check the exact script include names and parameters passed in your GlideAjax calls.

  • Always verify security permissions, especially if sensitive information is returned.


Choosing the right GlideAjax method significantly impacts performance and user experience. getXML() is generally preferred due to its asynchronous nature, enhancing user experience by maintaining form responsiveness. However, reserve getXMLWait() strictly for situations requiring immediate validation to prevent unwanted user actions. Following these best practices will help you create efficient and user-friendly ServiceNow applications.

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page