GlideAjax returning null

Kingstan M
Kilo Sage

Hi SNC,

GlideAjax returning null value.

Where i am doing wrong?

Script Include 

    checkTheExisingPachingRequest: function(AppServiceId, reqStartDate, reqEndDate) {
        
        var appserviceId = this.getParameter('sysparm_Appci') || AppServiceId;
        var sDate = this.getParameter('sysparm_reqStartDate') || reqStartDate;
        var eDate = this.getParameter('sysparm_reqEndDate') || reqEndDate;

        gs.log("appserviceId >> " + appserviceId);
        gs.log("sDate >> " + sDate);
        gs.log("eDate >> " + eDate);

Catalog Client Script

function onSubmit() {
    //Type appropriate comment here, and begin script below

    // >> topic >> getting boolen value server_patching_request
    var server_patching_request_true_or_false = g_form.getValue('server_patching_request');
    var application_choosen = g_form.getValue('application_service');
    var start_time_choosen = g_form.getValue('start_timestamp');
    var end_time_choosen = g_form.getValue('end_timestamp');

    //alert(server_patching_request_true_or_false + " >> " + g_form.getValue('application_service') + " >> " + g_form.getValue('start_timestamp') + " >> " + g_form.getValue('end_timestamp'));

    // >> topic >> initiate GlideAjax and pass the above values
    var gjx = new GlideAjax('WOWserverbookerUtils');
    gjx.addParam('sysparm_name', 'checkTheExisingPachingRequest');
    gjx.addParam('sysparm_Appci', application_choosen);
    gjx.addParam('sysparm_reqStartDate', start_time_choosen);
    gjx.addParam('sysparm_reqEndDate', end_time_choosen);
    gjx.getXML(CallBack);
    alert(JSON.stringify(gjx));

    function CallBack(response) {
        var output = response.responseXML.documentElement.getAttribute("answer");
        alert(output);
    }


}

1 ACCEPTED SOLUTION

Update the below line as below and try.

var arrAppServiceID = appserviceId.toString().split(',');

Replaced "AppServiceId" with "appServiceId".

 

Regards,
Muhammad

View solution in original post

17 REPLIES 17

MrMuhammad
Giga Sage

I just noticed that you are using GlideAjax in onSubmit client script that actually doesn't work with getXML (synchronous). 

Please have a look at below articles to understand the reason and for making it Asynchronous.

How To: Async GlideAjax in an onSubmit script | Blog

Asynchronous onSubmit Catalog/Client Scripts in ServiceNow

 

Regards,
Muhammad

I simply changed type from onSubmit to onChange.

It returns null still.

@kingstan 

Please update below lines as:

var appserviceId = AppServiceId ? AppServiceId : this.getParameter('sysparm_Appci');
var sDate = reqStartDate ? reqStartDate : this.getParameter('sysparm_reqStartDate');        
var eDate = reqEndDate ? reqEndDate : this.getParameter('sysparm_reqEndDate');

 

Regards,
Muhammad

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you are using asynchronous ajax in onSubmit so by the time the ajax function returns value the form might get submitted

Refer these links for solution

How to limit the total quantity of a shopping cart for a specific service catalog item in New York v...

Refer these links for workaround/solution on how to use Synchronous GlideAjax in onSubmit

How To: Async GlideAjax in an onSubmit script

Asynchronous onSubmit Catalog/Client Scripts in ServiceNow

Regards
Ankur

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

I tried with = getXMLWait 

Still it returns null.

++ @Muhammad 

 

Can you help me more on this topic?