
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
This blog presents a quick way to auto populate list collectors when they are dependent on other variables of the form. This is especially useful when list collectors have numbers of records that is greater than the default record count allowed in the UI.
Let's say that you have a form with a reference variable pointed towards groups tables and on selection of group, you want to display the members of the group in a list collector.
A simple way to do this is using a On-Change Client Script on the Groups variables and have a Script Include function to do the heavy lifting. Below is a sample Script Include function that queries the group membership table and retrieves all the members that are part of the selected group.
var Common_Utilities = Class.create();
Common_Utilities.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroupMembers : function(){
var group = this.getParameter('sysparam_groupID');
var user_array = [];
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('group',group);
getMembers.query();
while(getMembers.next())
{
var user_Obj = {};
user_Obj.key=getMembers.user.getDisplayValue();
user_Obj.value=getMembers.getValue('user');
user_array.push(user_Obj);
}
return (new JSON()).encode(user_array); //JSON formatted string
}
});
The script also shows how JSON can be used to return multiple values from Script Include function to Client Side functions for further manipulation.
Since we now have the details of the group members, we can call this script using GlideAjax from a On-change Client Script and populate the list collector variable. Below is the sample On-Change Client Script.
var varName = 'group_members'; //list collector variable name
var glideAjax = new GlideAjax('Common_Utilities');
glideAjax.addParam('sysparm_name','getGroupMembers');
glideAjax.addParam('sysparam_groupID',newValue);
glideAjax.getXMLWait();
var leftBucket = gel(varName + '_select_0');
var rightBucket = gel(varName + '_select_1');
rightBucket.options.length = '0'; //This will clear the right side bucket of list collector.
var response =(glideAjax.getAnswer());
var jsonData = (response.evalJSON());
for(var i=0 ; i < (jsonData.length) ; i++) //Loop through all the members
addOption(rightBucket,jsonData[i].value, jsonData[i].key); //Add the values to the right side bucket.
sortSelect(rightBucket); //Sort the bucket
leftBucket.onchange(); //This removes the values from left bucket that was added above
If you liked the content, please share, like, bookmark or leave your valuable comments.
- 3,399 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.