How to call script include from UI Page client script section ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2018 02:50 AM
Hello,
I need to make a call to script include from UI Page, when i try to invoke a function from client script of UI Page, it is not returning me anything, where as same thing works from catalog client script. please find the code snippet below.
$(document).ready(function() {
var ga = new GlideAjax("ControlVirtualMachinesAjax");
ga.addParam("sysparm_name", "getVMSInRG");
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
alert("ServerResponse: " + serverResponse);
}
});
Same code works perfect from catalog client script but not from client script of UI Page. In the above code , control never comes inside ajaxResponse method.
Thanks,
Krishna P
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2018 05:44 AM
Strange, Can you please remove the external libraries you have added in UI page and try it, This is straight & simple and ought to work.
Something is restricting/messing up with Glideajax libraries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2018 05:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2018 06:07 AM
HI,
Can you share the script inside script include, Just try with a single return statement.
Also, check logs for any error seen while a call is being made to the server.
Below link will also help to debug the issue.
https://community.servicenow.com/community?id=community_question&sys_id=782c4365db9cdbc01dcaf3231f96191c
Thanks
Gaurav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2018 03:42 AM
Hi Gaurav,
Sorry for the delay, here is my script include code.
var ControlVirtualMachinesAjax = Class.create();
ControlVirtualMachinesAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor,
{
_subscriptionId: "XXXXXXXXXXXXXXXXXXXXXXXXX",
_accessToken: null,
getVMSInRG : function(){
// Make sure we are connected and have access token
this._ensureAccessToken();
var rgName = this._getResourceGroupFromSysId(gs.getUserID());
gs.info("rgName: " + rgName);
var response = this._getVmList(this._accessToken, this._subscriptionId, rgName);
gs.info("After _getVmList, status code="+response.getStatusCode() +"response body="+response.getBody());
if(response) {
var output = new global.JSON().decode(response.getBody())["value"];
var size = output.length;
for(var i=0; i<size; i++){
var vm = output[i];
var vmName = vm["name"].toString();
var privateIPAddress = this._getPrivateIPAddress(this._accessToken, this._subscriptionId, rgName, vmName);
gs.info("name of the vm " + i + vmName);
var vmObject = this._getVmInfo(this._accessToken, this._subscriptionId, rgName, vmName);
gs.info("vmObject"+ i + new global.JSON().decode(vmObject.getBody()).properties.instanceView.statuses[1].displayStatus);
var vmNS = this.newItem("vmNS");
vmNS.setAttribute("status",new global.JSON().decode(vmObject.getBody()).properties.instanceView.statuses[1].displayStatus);
vmNS.setAttribute("ipAddress", privateIPAddress);
}
var vmList = new global.JSON().encode(response.getBody());
gs.info("getVMSInRG" + response.getBody());
var rg = this.newItem("rg");
rg.setAttribute("name", rgName);
return vmList;
}
return null;
},
type:"ControlVirtualMachinesAjax"
});
catalog client script works perfect with the above code, and also i have added following in UI Page
<script language="javascript" src="service.sn-glideAjax.jsdbx"/>
but in the console i am getting below error after adding above line in UI Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2018 04:03 AM
HI,
I am not sure how this will impact but can you try adding the service.sn_glideAjax.jsdbx to your UI page.(create a UI script first)
https://developer.servicenow.com/app.do#!/training/article/app_store_learn_advanced_ui_helsinki_c_ModuleAngularJS/app_store_learn_advanced_ui_helsinki_t_ExerciseCreateAjaxAdapter?v=helsinki
The error suggests that that the page couldn't load the Glideajax scripts.
https://developer.servicenow.com/app.do#!/training/article/app_store_learn_advanced_ui_helsinki_c_ModuleAngularJS/app_store_learn_advanced_ui_helsinki_t_ExerciseUpdateUIPageForGlideAjax?v=helsinki