
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 09:50 AM
Evening,
I have a catalogue item list collector variable where the user must specify a minimum of 2 users. If not, I want an alert message to tell them when they submit the request. With ref to the following post
https://community.servicenow.com/community?id=community_question&sys_id=bf4c4f65db9cdbc01dcaf3231f961969
I have created an onSubmit catalogue client script as follows:
function onSubmit() {
//Type appropriate comment here, and begin script below
var string = g_form.getValue('sp_group_add_owners');
var array = string.split(",");
if(array.length>1){
alert("less then 2");
}
else{
alert("2 or more");
}
}
However, there are two issues.
The first is that if I only select one user it returns the "2 or more" alert but still creates the request. ideally I want the user to have to go back and select at least one more before being able to submit.
The second is that it doesnt work on the portal. The request gets created regardless.
Any suggestions please?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 10:59 AM
Hi Cirrus,
Replace the code with the below and also make sure client script UI type field is set to ALL. In addition, you can also create a OnChange client script and alert the user when the field is modified and the value is less than 2. Edit: There was a typo error. Updated the script.
function onSubmit() {
//Type appropriate comment here, and begin script below
var string = g_form.getValue('sp_group_add_owners');
var array = string.split(",");
if(array.length < 2){
alert("less then 2");
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 10:59 AM
Hi Cirrus,
Replace the code with the below and also make sure client script UI type field is set to ALL. In addition, you can also create a OnChange client script and alert the user when the field is modified and the value is less than 2. Edit: There was a typo error. Updated the script.
function onSubmit() {
//Type appropriate comment here, and begin script below
var string = g_form.getValue('sp_group_add_owners');
var array = string.split(",");
if(array.length < 2){
alert("less then 2");
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 12:20 PM
Below script will stop the item from submission if list collector values is less than 2
var string = g_form.getValue('sp_group_add_owners');
var array = string.split(",");
if(array.length < 2 ){
return false
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2019 01:23 AM
Thanks Pradeep. Now works perfectly in the portal I had the UI set to Desktop!