List collector Archives - ServiceNow Guru https://servicenowguru.com/tag/list-collector/ ServiceNow Consulting Scripting Administration Development Tue, 28 May 2024 21:47:37 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.2 https://servicenowguru.com/wp-content/uploads/2024/05/cropped-SNGuru-Icon-32x32.png List collector Archives - ServiceNow Guru https://servicenowguru.com/tag/list-collector/ 32 32 Change the Size of a List Collector Slushbucket Variable https://servicenowguru.com/client-scripts-scripting/change-size-list-collector-slushbucket-variable/ https://servicenowguru.com/client-scripts-scripting/change-size-list-collector-slushbucket-variable/#comments Wed, 24 Nov 2010 08:33:06 +0000 https://servicenowguru.wpengine.com/?p=2830 List collector variables are a great way to collect multiple pieces of information about referenced records in a single variable in the Service Catalog. One complaint I get about these variables is that they take up a lot of space on the screen. While there’s not a lot you can do with regular slushbuckets in

The post Change the Size of a List Collector Slushbucket Variable appeared first on ServiceNow Guru.

]]>
List collector variables are a great way to collect multiple pieces of information about referenced records in a single variable in the Service Catalog. One complaint I get about these variables is that they take up a lot of space on the screen. While there’s not a lot you can do with regular slushbuckets in the system, List Collector variables have a little bit more flexibility because they can be manipulated with client scripts. Check out the SNGuru List Collector archives for more examples of cool List Collector modifications you can use.

In this article I’ll show you how you can reclaim some of that Service Catalog screen real estate by modifying the size of a list collector variable using a catalog client script.

Important note!!! Changing the size of your list collector has NO effect on the number of items displayed in that list collector. The number of entries in list collectors in your system is controlled by a global property. You can increase the number of entries in your filter, but that also incurs a performance hit when working with slushbucket filters since that whole number of items needs to be loaded every time in the slushbucket. You really don’t want to increase this number to much more than the default of 100.

The property is called ‘glide.xmlhttp.excessive’ and is documented here. It applies to all slushbuckets in your system (including those for list collectors).

The script is pretty simple. All you need to do is give it the name of the list collector variable you would like to resize, along with the width and height. In my testing I’ve found that the look of the variable can start to get kind of messy if you set a width less than 250 so I wouldn’t go any smaller than that.

As of the Winter 2010 Stable 2 release, it is now possible to hide the filter portion of a list collector variable completely. This can be accomplished by adding the ‘no_filter’ attribute to the ‘Attributes’ field on the variable form.
function onLoad(){
	var varName = 'YOUR_VARIABLE_NAME_HERE';
	var height = '100'; //Optional
	var width = '250'; //Optional
	try{
		//Get the left and right bucket input elements
		var leftBucket = $(varName + '_select_0');
		var rightBucket = $(varName + '_select_1');
		
		//If the element exists
		if(leftBucket){
			//Adjust the bucket height (default is 300px)
			if(height){
				leftBucket.style.height = height + 'px';
				rightBucket.style.height = height + 'px';
			}
			
			if(width){
				//Adjust the bucket width (default is 340px)
				leftBucket.style.width = width + 'px';
				rightBucket.style.width = width + 'px';
                                //Fix Fuji/Geneva width issue
                                leftBucket.up('.slushbucket').style.width = width*2 + 100 + 'px';
			}
			
			//Fix the expanding item preview issue
			$(varName + 'recordpreview').up('td').setAttribute('colSpan', '3');
		}
	}catch(e){}
}

Here’s the result!

The post Change the Size of a List Collector Slushbucket Variable appeared first on ServiceNow Guru.

]]>
https://servicenowguru.com/client-scripts-scripting/change-size-list-collector-slushbucket-variable/feed/ 28
Move List Collector Options https://servicenowguru.com/client-scripts-scripting/move-list-collector-options/ https://servicenowguru.com/client-scripts-scripting/move-list-collector-options/#comments Tue, 22 Jun 2010 15:42:14 +0000 https://servicenowguru.wpengine.com/?p=1758 Here’s a cool catalog client script that I figured out for a client. It allows you to move one or more selected options from one side of a list collector variable slushbucket to another. Using the script is pretty straight forward. Just supply the name of the list collector variable you are working with, and

The post Move List Collector Options appeared first on ServiceNow Guru.

]]>
Here’s a cool catalog client script that I figured out for a client. It allows you to move one or more selected options from one side of a list collector variable slushbucket to another. Using the script is pretty straight forward. Just supply the name of the list collector variable you are working with, and then make sure you provide an array of option IDs to move from one side to another. The option IDs need to be added to the ‘selectedIDs’ array in the middle chunk of code. The code below is set up to move ALL options in the right column of a slushbucket to the left.

//Name of variable to move options from
var varName = 'YOUR_VARIABLE_NAME_HERE';
var leftBucket = gel(varName + '_select_0');
var rightBucket = gel(varName + '_select_1');
var selectedOptions = rightBucket.options;

//Get an array of all option IDs to move
var selectedIDs = new Array();
var index = 0;
for(var i = 0; i < selectedOptions.length; i++){
   selectedIDs[index] = i;
   index++;
}

//Move all returned options from right to left bucket and sort the results
//Switch 'rightBucket' and 'leftBucket' to move from left to right
moveSelectedOptions(selectedIDs, rightBucket, leftBucket, '--None--');
//Sort the resultant options in the left bucket
sortSelect(leftBucket);

The post Move List Collector Options appeared first on ServiceNow Guru.

]]>
https://servicenowguru.com/client-scripts-scripting/move-list-collector-options/feed/ 35
Limiting Number of Selections in a List Collector https://servicenowguru.com/client-scripts-scripting/limiting-selections-list-collector/ https://servicenowguru.com/client-scripts-scripting/limiting-selections-list-collector/#comments Fri, 18 Jun 2010 13:47:43 +0000 https://servicenowguru.wpengine.com/?p=1743 List collector variables are a great way (currently the only way) to allow a user to select multiple options from a referenced table in a single variable on a service catalog item. The list collector variable allows you to choose from one to many (potentially hundreds or more) selections. What if you wanted to limit

The post Limiting Number of Selections in a List Collector appeared first on ServiceNow Guru.

]]>
List collector variables are a great way (currently the only way) to allow a user to select multiple options from a referenced table in a single variable on a service catalog item. The list collector variable allows you to choose from one to many (potentially hundreds or more) selections. What if you wanted to limit the number of items that a user could select? This script does exactly that. It restricts the selected items list on a list collector variable to whatever amount you choose. Just use the catalog client script below and set the variables for the maximum number of selections and the name of the variable to apply the restriction to.


Limit Selections Catalog Client Script
Name: Limit Selections
Type: onChange
UI type: Desktop
Script:

function onChange(control, oldValue, newValue, isLoading) {
//Limit the number of selected options in a list collector
//Specify the max options and variable name below
var maxOptions = 5;
var varName = 'users';
var leftBucket = gel(varName + '_select_0');
var rightBucket = gel(varName + '_select_1');
var selectedOptions = rightBucket.options;
if(selectedOptions.length > maxOptions){
//Move any options with IDs greater than maxOptions back to left bucket
var selectedIDs = [];
var index = 0;
for(var i = maxOptions; i < selectedOptions.length; i++){
selectedIDs[index] = i;
index++;
}
//Move options and sort the left bucket
moveSelectedOptions(selectedIDs, rightBucket, leftBucket, '--None--');
sortSelect(leftBucket);
alert('You cannot select more than ' + maxOptions + ' options.');
}
}

 

Service Portal version

With the introduction of the Service Portal UI, ServiceNow severely limits the client-side API that is available. That, in addition to the completely different UI of the list collector element itself, requires a different scripting approach. The following script is designed to work as a client script in Service Portal ONLY. Just make sure you change the ‘UI type’ field to ‘Mobile’ for this script.

Limit Selections Catalog Client Script (Service Portal version)
Name: Limit Selections
Type: onChange
UI type: Mobile
Script:

function onChange(control, oldValue, newValue, isLoading) {
//Limit the number of selected options in a list collector
//Specify the max options and variable name below
var maxOptions = 5;
var collectorName = 'users';
var myListCollector = g_list.get(collectorName);
var selectedOptions = g_form.getValue(collectorName).split(',');
if(selectedOptions.length > maxOptions){
//Remove the last item
myListCollector.removeItem(selectedOptions[selectedOptions.length-1]);
g_form.addErrorMessage('You cannot select more than ' + maxOptions + ' options.');
}
}

The post Limiting Number of Selections in a List Collector appeared first on ServiceNow Guru.

]]>
https://servicenowguru.com/client-scripts-scripting/limiting-selections-list-collector/feed/ 21
Customizing the Slushbucket https://servicenowguru.com/system-ui/customizing-slushbucket/ https://servicenowguru.com/system-ui/customizing-slushbucket/#comments Thu, 25 Feb 2010 20:47:01 +0000 https://servicenowguru.wpengine.com/?p=937 The term ‘Slushbucket’ is used in Service-now to refer to a couple of places in the system… The popup window view that you see when you click the ‘Edit’ button from a related list at the bottom of a form. The interface used to display any ‘List collector’ service catalog variable A question that comes

The post Customizing the Slushbucket appeared first on ServiceNow Guru.

]]>
The term ‘Slushbucket’ is used in Service-now to refer to a couple of places in the system…

  • The popup window view that you see when you click the ‘Edit’ button from a related list at the bottom of a form.
  • The interface used to display any ‘List collector’ service catalog variable

A question that comes up pretty often is “Can I customize the slushbucket to display more information about the items shown?”. The answer to this is ‘YES’ but it might not work exactly like you think it should. Currently, you only have control over the field values shown below the slushbucket when you click on any item to highlight it. The actual values shown in the slushbucket are determined by the ‘display’ field on the dictionary entry for the referenced table. Most people would like to display multiple columns worth of data for items within the slushbucket itself, but this is not possible yet.

Slushbucket Normal

Adding additional fields below the slushbucket is a very simple customization though. All you have to do is personalize the ‘sys_ref_list’ list view view for the table being displayed in the slushbucket.

So, if I was displaying a slushbucket with records from the ‘Group’ (‘sys_user_group’) table would need to personalize the ‘sys_ref_list’ list view for that table. There are a couple of ways you could do this, but the way I’ll show here ensures that your updates get captured correctly so they can be migrated to another instance if necessary.

For the ‘Group’ (‘sys_user_group’) table navigate to the following URL in your browser…

https://[YOUR_INSTANCE_URL]/sys_user_group_list.do?sysparm_view=sys_ref_list

This same convention can be used for any table in your system. Simply replace ‘sys_user_group’ with the table you want to personalize. Once you’re there, just right-click the list header and personalize the list.

Slushbucket sys_ref_list

Slushbucket Personalize List View

Any columns you add to the personalized ‘sys_ref_list’ view for a given table will be displayed below any slushbucket for that table.

Slushbucket Personalized

The post Customizing the Slushbucket appeared first on ServiceNow Guru.

]]>
https://servicenowguru.com/system-ui/customizing-slushbucket/feed/ 35
Changing the Filter of a List Collector Variable via Client Script https://servicenowguru.com/client-scripts-scripting/changing-filter-list-collector-variable-client-script/ https://servicenowguru.com/client-scripts-scripting/changing-filter-list-collector-variable-client-script/#comments Wed, 13 Jan 2010 23:28:22 +0000 https://servicenowguru.wpengine.com/?p=666 If you’ve worked with the Service-now.com service catalog much, you’ve probably realized that there are some differences between the service catalog interface and the traditional forms that are used throughout the rest of the tool. The intention of this is to make the experience a little bit better for end users of the system but

The post Changing the Filter of a List Collector Variable via Client Script appeared first on ServiceNow Guru.

]]>
If you’ve worked with the Service-now.com service catalog much, you’ve probably realized that there are some differences between the service catalog interface and the traditional forms that are used throughout the rest of the tool. The intention of this is to make the experience a little bit better for end users of the system but it also means that you, as an administrator, have to learn a few new tricks to deal with those differences.

One of these differences is the List collector variable. It allows the user to select multiple items from a list of items and optionally filter those items to help in their selection. One of the most common requests I see about this type of variable deals with how to handle the filter at the top of the list collector. Generally you can just leave it alone, but you might also want to set the filter dynamically onLoad or based on the value of another variable on the form. Depending on the situation and the number of items in the list collector table you may want to remove the filter portion completely.

List Collector - Filtered

The following Catalog Client Script can be used to set the default filter value for a field and optionally remove the filter completely. It assumes that your List collector variable is named ‘configuration_items’. By default it sets a filter where ‘name != null’ and ‘sys_class_name (CI type)’ is anything. Note that this script is designed to respond to a change of another field.

Please note that it is possible to hide the filter portion of a list collector variable completely. This can be accomplished by adding the ‘no_filter’ attribute to the ‘Attributes’ field on the variable form. The client script method may still be useful if you want to show/hide the filter conditionally however. This also works for Service Portal! Just make sure you set the ‘UI type’ field on the client script form to ‘Both’.

 

function onChange(control, oldValue, newValue, isLoading) {
//Apply a filter to the list collector variable
var collectorName = 'configuration_items';
var filterString = 'name!=NULL^sys_class_nameANYTHING';

//Try Service Portal method
try{
var myListCollector = g_list.get(collectorName);
myListCollector.reset();
myListCollector.setQuery(filterString);
}
//Revert to Service Catalog method
catch(e){
//Find and hide the filter header elements (optional)
//Simple method for items with only one list collector
//$('ep').select('.row')[0].hide();
//Advanced method for items with more than one list collector (more prone to upgrade failure)
//var el = $('container_' + g_form.getControl(collectorName).id).select('div.row')[0].hide();

//Reset the filter query
window[collectorName + 'g_filter'].reset();
window[collectorName + 'g_filter'].setQuery(filterString);
window[collectorName + 'acRequest'](null);
}
}
Note: If you are trying to filter your list collector in an onLoad script, you have to modify the script so that it waits for the list collector to be rendered before it sets the filter. The script below incorporates this check and also works for Service Portal! Just make sure you set the ‘UI type’ field on the client script form to ‘Both’.
function onLoad() {
//Apply a default filter to the list collector variable
var collectorName = 'configuration_items';
var filterString = 'name!=NULL^sys_class_nameANYTHING';

//Try Service Portal method
try{
var myListCollector = g_list.get(collectorName);
myListCollector.reset();
myListCollector.setQuery(filterString);
}
//Revert to Service Catalog method
catch(e){
//Hide the list collector until we've set the filter
g_form.setDisplay(collectorName, false);
setCollectorFilter();
}

function setCollectorFilter(){
//Test if the g_filter property is defined on our list collector.
//If it hasn't rendered yet, wait 100ms and try again.
if(typeof(window[collectorName + 'g_filter']) == 'undefined'){
setTimeout(setCollectorFilter, 100);
return;
}
//Find and hide the filter elements (optional)
//Simple method for items with only one list collector
//$('ep').select('.row')[0].hide();
//Advanced method for items with more than one list collector (more prone to upgrade failure)
//var el = $('container_' + g_form.getControl(collectorName).id).select('div.row')[0].hide();

//Reset the filter query
window[collectorName + 'g_filter'].reset();
window[collectorName + 'g_filter'].setQuery(filterString);
window[collectorName + 'acRequest'](null);
//Redisplay the list collector variable
g_form.setDisplay(collectorName, true);
}
}

The post Changing the Filter of a List Collector Variable via Client Script appeared first on ServiceNow Guru.

]]>
https://servicenowguru.com/client-scripts-scripting/changing-filter-list-collector-variable-client-script/feed/ 120