- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
I'm trying to convert List Collector sys_ids to user names using GlideAjax. The List Collector returns comma-separated sys_ids, which I pass to a client-callable Script Include. However, the GlideAjax response is always null.
Script include
var getwatchlistusernames = Class.create();
getwatchlistusernames.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getName: function() {
var ids = this.getParameter('sysparm_ids');
var names = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', 'IN', ids);
gr.query();
while (gr.next()) {
names.push(gr.getValue('name'));
}
return names.join(',');
},
type: 'getwatchlistusernames'
});
Catalog Client script
var ga = new GlideAjax('getwatchlistusernames');
ga.addParam('sysparm_name', 'getName');
ga.addParam('sysparm_ids', g_form.getValue('user'));
ga.getXMLAnswer(callback);
function callback(response) {
alert(response);
// g_form.setValue('short_description', response);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday - last edited Monday
Hi @NishmithaS ,
i looked into the your both script include and catalog client script. i have made one change in script include function name and it worked in my PDI
Script include:
var getwatchlistusernames = Class.create();
getwatchlistusernames.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getNames: function() { // getName changed to getNames
var ids = this.getParameter('sysparm_ids');
var names = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', 'IN', ids);
gr.query();
while (gr.next()) {
names.push(gr.getValue('name'));
}
return names.join(',');
},
type: 'getwatchlistusernames'
});
Catalog client script:
var ga = new GlideAjax('getwatchlistusernames');
ga.addParam('sysparm_name', 'getNames');// from getName to getNames
ga.addParam('sysparm_ids', g_form.getValue('user'));
ga.getXMLAnswer(callback);
function callback(response) {
alert(response);
// g_form.setValue('short_description', response);
}
can you try this and let me know still your getting null as the resposne
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday - last edited Monday
Hi @NishmithaS ,
i looked into the your both script include and catalog client script. i have made one change in script include function name and it worked in my PDI
Script include:
var getwatchlistusernames = Class.create();
getwatchlistusernames.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getNames: function() { // getName changed to getNames
var ids = this.getParameter('sysparm_ids');
var names = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', 'IN', ids);
gr.query();
while (gr.next()) {
names.push(gr.getValue('name'));
}
return names.join(',');
},
type: 'getwatchlistusernames'
});
Catalog client script:
var ga = new GlideAjax('getwatchlistusernames');
ga.addParam('sysparm_name', 'getNames');// from getName to getNames
ga.addParam('sysparm_ids', g_form.getValue('user'));
ga.getXMLAnswer(callback);
function callback(response) {
alert(response);
// g_form.setValue('short_description', response);
}
can you try this and let me know still your getting null as the resposne
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
Hi @Bhavya11
Thank you so much. It worked after I changed the function name.
I have one question Is there any reason getName wouldn't work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
Hi @NishmithaS ,
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
Hi @NishmithaS ,
1- Ensure the Client callable checkbox is checked on the Script Include.
2 - Verify the List Collector value
Before calling GlideAjax, check what you're actually sending:
alert(g_form.getValue('user'));
this return like this = 46d44...,8f3b2...,a1234...
3 - Use getDisplayValue() instead of getValue()
-
The
namefield is not always the display value. Try:names.push(gr.getDisplayValue());ORR
names.push(gr.getDisplayValue('name'));
4= add Logs in your scritp include
gs.info("IDs: " + ids);