How to auto populate list collector variable using on Load client script and script include

Alon Grod
Tera Expert

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'

});

 

1 ACCEPTED SOLUTION

Hi @Alon Grod 

 

can you try to update Variable attribute to  "glide_list"

 

VishalBirajdar7_0-1694416656440.png

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Alon Grod 

since you want this to happen on form load, why not use default value for that variable?

I assume requested_for must be populated with logged in user? If yes then you can use default value

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar how can I achieve that using default value? the default value should be the list field 'u_ramad' from u_ou table.

@Ankur Bawiskar the default value should be dynamic according to the requested for users but it should also be on change (if the user changes the requested for after on Load)

@Alon Grod 

why to use attribute glide_list?

It will only show as glide list in native but on portal side it will be normal list collector

check my blog on how to auto populate list collector based on another variable

Dynamically set list collector on change of variable 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader