- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2019 12:44 AM
Hi I am trying to pull some server side values to client side for use in UI Action(client side) using client callable script include. And getting a null value in the answer. Below are my both of the codes
UI Action(Form button, client, onClick function - commentsDialog())
function commentsDialog() {
//Get the values to pass into the dialog
var caller = g_form.getReference('caller_id', doAlert);
}
function doAlert(caller) {
var location = caller.location;
var ci = g_form.getValue('cmdb_ci');
var ga = new GlideAjax("TogetModelAndLocationName");
ga.addParam("sysparm_name", "getName");
ga.addParam("sysparm_ci", ci);
ga.addParam("sysparm_loc",location);
ga.getXML(Callback);
//alert(ga.getAnswer().toString());
}
function Callback(response){
//var answer = JSON.parse(response);
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
Script Include(client callable)
var TogetModelAndLocationName = Class.create();
TogetModelAndLocationName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getName: function(){
var modelname = '';
var locationname = '';
var name = '';
var sysId = this.getParameter('sysparm_ci');
var locsysID = this.getParameter('sysparm_loc');
var model = new GlideRecord( 'cmdb_ci' );
model.addQuery('sys_id',sysId);
model.query();
if( model.next() ){
modelname = model.model_id.display_name;
}
var location = new GlideRecord('cmn_location');
location.addQuery('sys_id',locsysID);
location.query();
if(location.next()){
locationname = location.name;
}
name = modelname+','+locationname;
gs.log(name,'air');
return name;
},
type: 'TogetModelAndLocationName'
});
When I execute UI Action, it gives me a "null" as alert but the log generated from Script Include gives correct values. I tried JSON encoding of the return value and also tried synchronous call both result in no alerts.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2019 01:31 AM
Hi AirSquire,
Client Script:
function commentsDialog() {
//Get the values to pass into the dialog
var caller = g_form.getReference('caller_id', doAlert);
// alert((g_form.getReference('caller_id').name));
}
function doAlert(caller) {
var location = caller.location;
var ci = g_form.getValue('cmdb_ci');
var ga = new GlideAjax("TogetModelAndLocationName");
ga.addParam("sysparm_name", "getName");
ga.addParam("sysparm_ci", ci);
ga.addParam("sysparm_loc",location);
ga.getXML(callback);
}
function callback(response){
var answer = response.responseXML.documentElement.getAttribute("name"); // Changed this
alert(answer);
}
Include:
var TogetModelAndLocationName = Class.create();
TogetModelAndLocationName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getName: function(){
var modelname = '';
var locationname = '';
var name = '';
var sysId = this.getParameter('sysparm_ci');
var locsysID = this.getParameter('sysparm_loc');
var model = new GlideRecord( 'cmdb_ci' );
model.addQuery('sys_id',sysId);
model.query();
// gs.log('CI count: '+model.getRowCount());
if( model.next() ){
modelname = model.model_id.display_name;
}
var location = new GlideRecord('cmn_location');
location.addQuery('sys_id',locsysID);
location.query();
gs.log('LOC count: '+location.getRowCount());
if(location.next()){
locationname = location.name;
}
name = modelname+','+locationname;
this.getRootElement().setAttribute('name', name); // Changed this
},
type: 'TogetModelAndLocationName'
});
See this post: Glide Ajax returns null from Mahendra.
Quickly tested on my DEV - seems to work fine.
Hope this helps.
Cheers!
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2019 01:30 AM
No luck, I changed
modelname = model.model_id.getDisplayValue();
locationname = location.getDisplayValue();
Still logs are same and fine. And the alert is null.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2019 01:39 AM
Can you verify, that both parameters have correct value in the Script Include?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2019 01:31 AM
Hi AirSquire,
Client Script:
function commentsDialog() {
//Get the values to pass into the dialog
var caller = g_form.getReference('caller_id', doAlert);
// alert((g_form.getReference('caller_id').name));
}
function doAlert(caller) {
var location = caller.location;
var ci = g_form.getValue('cmdb_ci');
var ga = new GlideAjax("TogetModelAndLocationName");
ga.addParam("sysparm_name", "getName");
ga.addParam("sysparm_ci", ci);
ga.addParam("sysparm_loc",location);
ga.getXML(callback);
}
function callback(response){
var answer = response.responseXML.documentElement.getAttribute("name"); // Changed this
alert(answer);
}
Include:
var TogetModelAndLocationName = Class.create();
TogetModelAndLocationName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getName: function(){
var modelname = '';
var locationname = '';
var name = '';
var sysId = this.getParameter('sysparm_ci');
var locsysID = this.getParameter('sysparm_loc');
var model = new GlideRecord( 'cmdb_ci' );
model.addQuery('sys_id',sysId);
model.query();
// gs.log('CI count: '+model.getRowCount());
if( model.next() ){
modelname = model.model_id.display_name;
}
var location = new GlideRecord('cmn_location');
location.addQuery('sys_id',locsysID);
location.query();
gs.log('LOC count: '+location.getRowCount());
if(location.next()){
locationname = location.name;
}
name = modelname+','+locationname;
this.getRootElement().setAttribute('name', name); // Changed this
},
type: 'TogetModelAndLocationName'
});
See this post: Glide Ajax returns null from Mahendra.
Quickly tested on my DEV - seems to work fine.
Hope this helps.
Cheers!
Martin