- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 05:49 AM
Hi,
I have a requirement to remove list collector selected values if we selection is more than 3 values.
I should be able to enter the 4th value the list collector should not accept the 4th value when the user enters beyond 3 values. It should remove the additional selected value. I am try to achieve this using the onChange - Client Script. Can this be achieved?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 06:07 AM
Hi @Hari1 ,
You Can use below onChange client script for that :-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var values = g_form.getValue('work_notes_list').toString().split(',');
//g_form.addInfoMessage('total value in users ' + values);
if (values.length > 3) {
alert('Please select only 3 choices');
//g_form.removeOption('who_are_need_to_access','value');
for (var i = 0; i < 3; i++) {
g_form.setValue('work_notes_list', values[i]);
}
return values;
}
}
Replace your field wherever 'work_notes_list' is written.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 06:00 AM
Hi @Hari1 ,
write onSubmit catalog client script
Applies to Catalog Item
Applies on Catalog Item view - True
UI Type = ALL
Note: give your list collector variable name below
function onSubmit()
var values = g_form.getValue('variableName').toString().split(',');
if(values.length > 3){
alert('Please select only 3 choices');
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 06:05 AM
I would something on the OnChange Client Script.
Below is the code that i am currently using.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var appCount = g_form.getValue('applications_to_be_updates_is_more_than_5');
var appList = g_form.getValue('select_the_application_name');
if(appCount == 'Yes' && appList.split(",").length > 3){
alert("You cannot add more than 3 applications");
appList.split(",").splice(appList.split(",").indexOf(appList.split(",")[3]), 1);
//appList.removeItem(appList.split(",")[3]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 06:16 AM - edited ‎11-08-2022 06:20 AM
Hi @Hari1 ,
Try below script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var appCount = g_form.getValue('applications_to_be_updates_is_more_than_5');
var appList = g_form.getValue('select_the_application_name');
var app = appList.split(",");
if(appCount == 'Yes' && app.length > 3){ //If you want this to depend on appCount then fine else revie appCount check
alert("You cannot add more than 3 applications");
app.pop() // THis will removet the recent selection
g_form.clearValue("select_the_application_name");
g_form.setValue("select_the_application_name",app); // repopulate with 3 values
}
}
In case if you want this to be dependent on count of app only then use below code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var appList = g_form.getValue('select_the_application_name');
var app = appList.split(",");
if(app.length > 3){
alert("You cannot add more than 3 applications");
app.pop() // This will removet the recent selection
g_form.clearValue("select_the_application_name");
g_form.setValue("select_the_application_name",app); // repopulate with 3 values
}
}
I hope this help.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2022 06:07 AM
Hi @Hari1 ,
You Can use below onChange client script for that :-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var values = g_form.getValue('work_notes_list').toString().split(',');
//g_form.addInfoMessage('total value in users ' + values);
if (values.length > 3) {
alert('Please select only 3 choices');
//g_form.removeOption('who_are_need_to_access','value');
for (var i = 0; i < 3; i++) {
g_form.setValue('work_notes_list', values[i]);
}
return values;
}
}
Replace your field wherever 'work_notes_list' is written.