How to call function present in server Ajax processsor from client script.

mouli7
Tera Contributor

Hi,

i need to call  showCalender() function from client script.
How to call it?


mouli7_0-1720707109715.png

i already know how to pass parameters from client:

 

 

      schedulePage.addParam("myParam","myParamValue");

      schedulePage.run();

 


but i don't know how return values from the  server ajax.

that's why i need to know how functions can be called.

 

Thanks.

 

3 REPLIES 3

Its_Azar
Tera Guru

Hi there @mouli7 

 

makee your Script Include is client-callable by extending AbstractAjaxProcessor.

Create the function showCalendar within the Script Include

 

 

var SchedulePage = Class.create();
SchedulePage.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    showCalendar: function() {
        var result = {}; 
   
        return JSON.stringify(result);
    }
});

 

 

 Use the GlideAjax class to call the server-side function from the client script.

 

 

function callShowCalendar() {
    var ga = new GlideAjax('SchedulePage'); 
    ga.addParam('sysparm_name', 'showCalendar'); 
    ga.getXMLAnswer(handleResponse);
}

function handleResponse(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    var result = JSON.parse(answer);
    console.log(result); 
}

// Call the function
callShowCalendar();

 

 

 

If this helps upvote and kindly accept the response. 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.




Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

 Microsoft MVP (AI Services), India

mouli7
Tera Contributor

this solution you given is to crate a script include and making  a call 
but my question how to use the server ajax processor present in the screen shot.

Community Alums
Not applicable

Hi @mouli7 ,

Please check below community links for same problem

https://www.servicenow.com/community/developer-forum/how-to-call-an-ajax-script-include-from-a-busin...

https://www.servicenow.com/community/developer-forum/calendar-schedule-page-passing-parameters-from-...

 

Please mark my answer correct and helpful if this works for you

Thanks andRegards 

Sarthak