- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2023 11:04 PM
Hi,
I have the List collector variable called 'u_ramad' that is a reference to the sys_user table. I have the field 'u_ramad' of type List (reference to sys_user table as well) in my 'u_ou' table.
I need to write onLoad client script that called a script include which return the values from the list field 'u_ramad' from the u_ou table. These values should be populated automatically in the right bucket of the 'u_ramad' list collector variable.
function onLoad() {
var user = g_form.getvalue('requested_for');
var ga = new GlideAjax('fill Ramad');
ga.addParam( sysparm_name, isRamad);
ga.addParam('sysparm_std', user);
ga.getXML(getResponse);
function getResponse(response) {
var ans = response.responseXML.documentElement.getAttribute("answer');
alert(ans);
if(ans != '') {
g_form.setvalue('u_ramad', ans);
}
}
Script include:
var fillRamad = Class.create();
fillRamad.prototype object.extendsObject(AbstractAjaxProcessor, {
isRamad: function() {
var us = this.getParameter('sysparm_std');
var gr= new GlideRecord('sys_user);
gr.addEncodedQuery('sys_id='+us.toString());
gr.query();
if(gr.next()) {
var hi = gr.u_hierarchy.toString();
hi = hi.split('/')[0];
var sp= new GlideRecord('u_ou');
sp.addEncodedQuery('u_ou=' + hi);
sp.query();
if(sp.next()) {
return sp.u_ramad.toString();
}
},
type: 'fillRamad'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 12:17 AM
Hi @Alon Grod
can you try to update Variable attribute to "glide_list"
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2023 11:57 PM - edited ‎09-10-2023 11:58 PM
Hi @Alon Grod
Can you try below code ...!! Just modified some things in your code
Step 1 : onChange script on requested for
var user = g_form.getValue('requested_for');
g_form.addInfoMessage('user=' + user);
var ga = new GlideAjax('fillRamad');
ga.addParam('sysparm_name', "isRamad");
ga.addParam('sysparm_std', user);
ga.getXMLAnswer(getResponse);
function getResponse(answer) {
g_form.addInfoMessage(answer);
if (answer) {
g_form.setValue('u_ramad', answer);
}
}
Step 2 : Client callable script include
isRamad: function() {
var result;
gs.log("fillrmad= inside script include");
var us = this.getParameter('sysparm_std');
gs.log("fillrmad= US=" + us);
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('sys_id=' + us);
gr.query();
if (gr.next()) {
var hi = gr.u_hierarchy.toString();
hiSplit = hi.split('/')[0];
var sp = new GlideRecord('u_ou');
sp.addEncodedQuery('u_ou=' + hiSplit);
sp.query();
if (sp.next()) {
gs.log("fillramad=" + sp.u_ramad.toString());
result = sp.u_ramad.toString();
}
}
return result;
},
Output :
Record in the OU table
Same users will be displayed on "Ramad" variable
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 12:10 AM
@Vishal Birajdar what is the field type of Ramad variable that you created in the catalog item? How did you make it as a List?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 12:13 AM
@Vishal Birajdar I can only make it as a list collector
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 12:17 AM
Hi @Alon Grod
can you try to update Variable attribute to "glide_list"
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates