GlideAjax is not working in Service Portal Widget (Istanbul)

brian_corpuz
Tera Expert

I am looking into creating a utility script include that can be used across any widgets to be created for a specific application. I tried to test a basic call for the server-side script, the script include using GlideAjax, unfortunately, it's not working. I am using Istanbul instance.

Client-Scripting

var gTest = new GlideAjax('TDisplayMessage');

gTest.addParam('sysparm_name', 'displayMessage');

gTest.getXML(displayMessage);

function displayMessage(response){

      alert(response.responseXML);         <----- still the result is null (no XML received)

}

Script Include

var TDisplayMessage = Class.create();

TDisplayMessage.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

        displayMessage: function(){

                  return "Hello Greeting!";

        },

        type: 'TDisplayMessage'

});

1 ACCEPTED SOLUTION

Hi Nagendra,



Yes, I followed the steps mentioned in SN documents as well as verified the construction from other threads.



It seems there is a missing link, or a plugin that needs to be activated, or another script that should be imported in order to make GlideAjax work in the service portal widget.



Or, am I doing it wrong? Is there a different coding approach in the widget's client script?


View solution in original post

9 REPLIES 9

brian_corpuz
Tera Expert

This has been resolved!



Points to consider:


1. Script include function(s) are only accessible in the Server Script of the widget. The class object can be directly initialized without using GlideAjax.


2. Client script calling Server Script method is possible using c.server.get



SCRIPT INCLUDE:


********************************************************************************************************************


var TestServerScriptOnLoad = Class.create();



TestServerScriptOnLoad.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {


      testServiceScriptOnLoad: function(){


              console.log('Entered the script include--> TestServerScriptOnLoad');


      },      


      type:"TestServerScriptOnLoad"


});


********************************************************************************************************************


SERVER SCRIPT:


********************************************************************************************************************


(function() {


      console.log('See if this function is initially loaded.');


     


      testOnLoad();


     


      if(input){


                      if(input.action == 'getServerScriptMethod'){


                              console.log('Called from client script-->getServerScriptMethod:'+input.param);


                      }


      }


})();



function testOnLoad(){


      console.log('Check if this function is being called--testOnLoad()');


     


      var ga = new TestServerScriptOnLoad();


      ga.testServiceScriptOnLoad();


}


********************************************************************************************************************


CLIENT SCRIPT:


********************************************************************************************************************


function onLoad(){


      var c = this;


     


      console.log('Calling the client script of the widget.');


     


      callServerScript(c);


}



function callServerScript(c){


      c.server.get({


              action:"getServerScriptMethod",


              param:"ClientScript"}).then(function(response){},   callErrorMessage());


}



function callErrorMessage(){


      console.log('Displaying error message.');


}


********************************************************************************************************************


In your research and testing, did you happen to come across anything about using glide ajax from a ui script included in the theme? I *think* glide ajax is either broken or intentionally not supported in all aspects of the portal even though i can find some community posts saying it is supported.


Well, synchronous Glide Ajax is not supported in Portal, asynchronous Glide Ajax works as usual.

I know this is REALLY old. The issue we were/are having is specifically when the ajax call (getXML, not getXMLWait) lives in script included in the portal's theme.

 

We got around it by PASSING the g_form object from the catalog client scripts into the included UI scripts.

@robertyoung Could you elaborate a little or show example code of what you did?  Same situation here where I added a UI Script to an SP Theme.  Trying to use a GlideAjax call in a UI Script.  (see this post)