The Now Platform® Washington DC release is live. Watch now!
‎07-07-2017 01:13 AM
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'
});
Solved! Go to Solution.
‎07-09-2017 08:45 PM
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?
‎07-07-2017 03:43 AM
Hi Brian,
If you are creating any utility then you should call that script include(by creating an object of script inclue) in server script of widgets and then we can use the value in client side as well.
Hope this helps.
Regards
Ujjawal
‎07-09-2017 08:41 PM
Hi Ujjawal,
Appreciate the response.
Well, this is a good idea but has negative impact in the future. This utility is to be used by multiple widgets, if I am to put into the server script, I need to do the same coding for the rest of the widgets.
I am creating a single utility which can be used across all the widgets that will be using it. If there is any modification, I only need to modify 1 set of code instead of modifying the widgets affected by the changes.
Hope I am able to give you the picture of my idea in this question.
‎07-07-2017 04:04 AM
Hi Brian,
Did you checked the Client Callable option in Script Include ?
And also update your code as below to get proper response
var gTest = new GlideAjax('TDisplayMessage');
gTest.addParam('sysparm_name', 'displayMessage');
gTest.getXML(displayMessage);
function displayMessage(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
Thanks,
Nag.
‎07-09-2017 08:45 PM
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?