- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 01:57 PM
Hello dear experts,
I want to display a short description field if there are more than 3 options selected in the right bucket of the list collector, but my code isn't working in the service portal. Its probably because the gel function doesn't work for portal. The below is the code that works in the native view and doesn't in the Service Portal:
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading)
return;
var varName = 'swItem_costcenter';
var rightBucket = gel(varName + '_select_1');
var selectedOptions = rightBucket.options;
var len = selectedOptions.length;
// Determine if more than 1 cost center is selected, if so cost distribution should be determined
if( len > 1){
g_form.setDisplay('swItem_cost_distribution', true);
g_form.setMandatory('swItem_cost_distribution', true);
}else{
g_form.setDisplay('swItem_cost_distribution', false);
g_form.setMandatory('swItem_cost_distribution', false);
g_form.setValue('swItem_cost_distribution', '');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 05:33 AM
Thanks everyone. I was able to do this with the use of of the Split function. Values in the right bucket in the List Collector are separated by commas. I was able to make use of that fact.
Here's the code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setDisplay('swItem_cost_distribution', false);
g_form.setMandatory('swItem_cost_distribution', false);
g_form.setValue('swItem_cost_distribution', '');
return;
}
value = g_form.getValue('swItem_costcenter');
len = value.split(',').length;
// Determine if more than 1 cost center is selected, if so cost distribution should be determined
if( len > 1){
g_form.setDisplay('swItem_cost_distribution', true);
g_form.setMandatory('swItem_cost_distribution', true);
}else{
g_form.setDisplay('swItem_cost_distribution', false);
g_form.setMandatory('swItem_cost_distribution', false);
g_form.setValue('swItem_cost_distribution', '');
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Thanks again everyone!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 10:19 PM
Use the length command to calculate number of options selected.
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading)
return;
var len = g_form.getValue('<variable name of list collector>').length;
// Determine if more than 1 cost center is selected, if so cost distribution should be determined
if( len > 1){
g_form.setDisplay('swItem_cost_distribution', true);
g_form.setMandatory('swItem_cost_distribution', true);
}else{
g_form.setDisplay('swItem_cost_distribution', false);
g_form.setMandatory('swItem_cost_distribution', false);
g_form.setValue('swItem_cost_distribution', '');
}
}
This onChange script will run when ever you are selected the option from left to right.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 05:33 AM
Thanks everyone. I was able to do this with the use of of the Split function. Values in the right bucket in the List Collector are separated by commas. I was able to make use of that fact.
Here's the code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setDisplay('swItem_cost_distribution', false);
g_form.setMandatory('swItem_cost_distribution', false);
g_form.setValue('swItem_cost_distribution', '');
return;
}
value = g_form.getValue('swItem_costcenter');
len = value.split(',').length;
// Determine if more than 1 cost center is selected, if so cost distribution should be determined
if( len > 1){
g_form.setDisplay('swItem_cost_distribution', true);
g_form.setMandatory('swItem_cost_distribution', true);
}else{
g_form.setDisplay('swItem_cost_distribution', false);
g_form.setMandatory('swItem_cost_distribution', false);
g_form.setValue('swItem_cost_distribution', '');
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Thanks again everyone!