slecect only one country at the time in Variable(LIST COLLECTOR) in variable set

PRADEEPREDDY GU
Tera Expert

the requstor has the option to select multiple countries in {VARIABLE SET}affected coountry(LISTCOLLECTOR) field, Please make sure requestor allowed to slecect only one country .at the time for only single catalog item.

 

PFB...

 
 

 

 

PRADEEPREDDYGU_0-1760703863128.png

 

 

 

6 REPLIES 6

Connectmustaq
Giga Guru

Hi @PRADEEPREDDY GU ,

 

Greetings for the Day!!
To restrict the "affected country" variable (which is currently a list allowing multiple selections) to only allow a single country selection at a time for a specific catalog item in ServiceNow, you have a few options. The best approach depends on how your variable is defined, but typically, you can enforce this through variable type configuration or scripting.

There are three ways you can do it

 

1. Change Variable Type to Single-Select:
  • If the variable is currently a List Collector (multi-select), consider changing it to a Single-Select Choice List.
  • For example:
    • Variable Type: Select Box (Single Choice)
    • Populate options with the list of countries.
This ensures only one country can be selected directly via the variable configuration.
2. Add Client Script to Restrict Multi-Select Behavior for a Specific Catalog Item
If you need to retain List Collector but restrict it to only one selection per request, you can add a Client Script on the Catalog Item:
// Client Script (onChange or onLoad)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Assume variable name is 'affected_country' (replace with your variable name)
var selectedValues = g_form.getValue('affected_country');
// If multiple values are selected, clear the selection and alert user
if (selectedValues.includes(',')) {
g_form.setValue('affected_country', newValue.split(',')[0]);
alert('Please select only one country.');
}
}
  • The above script enforces only the first selection remains if multiple are selected.
  • You would need to set this script on the catalog item variables.
3. Use Variable Set Client Script to Control Selection
  • You can also add a Client Script to disable multiple selections after initial choice.
  • Or, prevent users from selecting multiple options by customizing the List Collector variable to behave as a dropdown.
Best Practice:
If only a single country should ever be selected, changing the variable type to a "Select Box" (single choice) is the most straightforward and user-friendly approach.

If it is helpful, please hit the thumbs button and accept the correct solution by referring to this solution in the future it will be helpful to them.

 

Thanks & Regards,

Mohammed Mustaq Shaik

Hi,thanks  for sharing details.

 

could u plz advice me how to to use ina variable set variable fied for particular catalog item.
i tried but not working help me on this 

 

Hi @PRADEEPREDDY GU ,

  • Best Practice: Change List Collector to single-select by unchecking "Allows Multiple Selections" on that variable for your catalog item.

  • If not possible, enforce selection limitation with a client script validating on submission.

Set the List Collector to Single-Select Mode for That Item

  1. Navigate to the Catalog Item

    • Go to the specific catalog item form where the affected country variable set is used.

  2. Locate the List Collector Variable

    • Find the List Collector variable inside the Variable Set named affected country.

  3. Set the List Collector to Single Select

    • Open the List Collector variable record.

    • Find the checkbox or option called "Allows Multiple Selections" and uncheck it. This converts the List Collector into a single-select dropdown.

  4. Conditionally Apply for Single Catalog Item Only
    Since you want this restriction only for a particular catalog item:

    • You can create a separate List Collector variable configured for single selection.

    • Replace the multi-select List Collector only on that item.

    • Or, if using the same variable set across catalog items, apply a Catalog Client Script on that item to enforce the single selection behavior dynamically (e.g., by disabling further selections).

If you cannot change the variable configuration, use a Catalog Client Script on the catalog item:

function onSubmit() {
var selectedCountries = g_form.getValue('affected_country'); // use your variable name
if (selectedCountries && selectedCountries.indexOf(',') !== -1) {
alert('Please select only one country.');
return false; // block submission
}
return true;
}

This script checks if more than one country was selected (multi-select returns values separated by commas) and prevents submission with an alert.

 

please mark the answer as correct and helpful based on the impact!!

Kind Regards,

Shaik Mohammed Mustaq

Ankur Bawiskar
Tera Patron
Tera Patron

@PRADEEPREDDY GU 

So you are saying when RITM001 was submitted the Country was Albania

Now when user again is submitting the item this Country should not be allowed to select?

 

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