THURSDAY, FEBRUARY 09, 2012

Limiting Number of Selections in a List Collector

L

ist 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
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 = new Array();
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.')
}
}

Comments

Posted On
Jul 09, 2010
Posted By
Joe

Very cool, love this trick!

Posted On
Aug 12, 2010
Posted By
computerdr74

This is pretty cool. Can you do something similar with a slushbucket on an incident child ticket related list? For example, if you use the “Edit..” button and you get a slushbucket of available incidents to apply to the parent, I want to create a confirmation popup that will warn them before they submit the selected incidents. I’ve tried to find the code for the “save” and “cancel” buttons on this form. I could tie in some code to the “save” button. But in the html, it specifies it as the sysverb_save id. I can’t find this anywhere. It’s probably right in front of my face. Anyway, if you could provide something similar to what you did above for my scenario, that would be awesome and much appreciated. Thanks!

Posted On
Aug 12, 2010
Posted By
Mark Stanger

Unfortunately, you can’t run client scripts on the standard slushbucket interface without some pretty bad hacks. That interface is locked down so that there’s nothing you can do with it really aside from setting a default filter and customizing the columns that show below the slushbucket.

Posted On
Jan 24, 2012
Posted By
Matt Farahmand

Mark,
Is there a way to gain access to the slush bucket values within a script and do a dot walk to the reference table based on that selected value?! Here is an example;
I pick an application from left to right and then be able to identify this selected application and dot walk to its reference table.

Posted On
Jan 24, 2012
Posted By
Mark Stanger

There’s not a way to do that directly since the values are just a comma-separated string. You would have to get the value, parse the sys_id, and then query for the record.

Posted On
Feb 08, 2012
Posted By
ND

Hi Mark,

This is cool.

How can I do same at the form level. I have created a slushbucket variable and I want to get the value selected using client script (onLoad & onChange). I used similar approch , but it didn’t worked.

var varName = ‘u_yla_equipment_size’;
var leftBucket = gel(varName + ‘_select_0′);
var rightBucket = gel(varName + ‘_select_1′);
var selectedOptions = rightBucket.options;
alert(selectedOptions);

This is my onLoad code, I am not even getting alert popup. Could you please suggest me how to get the values of the selected items in slushbucket in form, so that I can make other dependent fields mandatory ( Based on selection).

Regards,
ND

Leave a Reply


Notify me of followup comments via e-mail. You can also subscribe without commenting.

Latest Comments

  • Aric: Finally figured out what I was doing wrong, incase someone else wants to do this. Mark is correct about needing...
  • Mark Stanger: You’ll probably need at least 3 total ACLs then. You’ll need one...
  • Mark Stanger: Hey Paul, I assume you’re talking about ‘task_ci’, not ‘task_group. If so, the...
  • ND: Hi Mark, This is cool. How can I do same at the form level. I have created a slushbucket variable and I want to...