- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2020 01:19 AM
Hello All,
I have requirement to make fields visible based the selection in the list collector variable.
List collector variable is populating from the 'file system' table.
so if someone selects one option in the right bucket, then one field should be visible and if someone selects two options, two fields should be visible.
Please assist me that How can I read the selections so that fields can be visible.
I think catalog client script should be written to make the filed visible but have no proper solution.
Please provide some solution.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2020 03:45 AM
Hi,
don't use gel() it won't work in portal
In below script use your valid variable names and list collector variable name
1) Use onchange and onSubmit
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var value = g_form.getValue('user'); // your list collector variable name here
var len = value.toString().split(',').length;
if(len == 1){
// show your variable
g_form.setMandatory('second',false);
g_form.setMandatory('first',true);
g_form.setVisible('first',true);
g_form.setVisible('second',false);
}
else if(len == 2){
// show your variables
g_form.setMandatory('first',true);
g_form.setMandatory('second',true);
g_form.setVisible('first',true);
g_form.setVisible('second',true);
}
}
2) onSubmit
function onSubmit(){
var value = g_form.getValue('user'); // your list collector variable name here
var len = value.toString().split(',').length;
if(len > 2){
alert('You are only allowed to select 2 values');
return false;
}
//Type appropriate comment here, and begin script below
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2020 03:45 AM
Hi,
don't use gel() it won't work in portal
In below script use your valid variable names and list collector variable name
1) Use onchange and onSubmit
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var value = g_form.getValue('user'); // your list collector variable name here
var len = value.toString().split(',').length;
if(len == 1){
// show your variable
g_form.setMandatory('second',false);
g_form.setMandatory('first',true);
g_form.setVisible('first',true);
g_form.setVisible('second',false);
}
else if(len == 2){
// show your variables
g_form.setMandatory('first',true);
g_form.setMandatory('second',true);
g_form.setVisible('first',true);
g_form.setVisible('second',true);
}
}
2) onSubmit
function onSubmit(){
var value = g_form.getValue('user'); // your list collector variable name here
var len = value.toString().split(',').length;
if(len > 2){
alert('You are only allowed to select 2 values');
return false;
}
//Type appropriate comment here, and begin script below
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader