
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 08:58 AM
Please could someone advise how to solve this.
I have a catalog item with a list variable, and I want to be able to count the number of elements selected, but if certain items are added to the list, I want to exclude these from the count. I already have two on change scripts doing similar things:
To count all items:
value = g_form.getValue('catalogue');
len = value.split(',').length;
g_form.setValue('count', len);
And to manage behaviours based on items selected:
var flg = 'false';
//check the list collect doesnt contain any free items or is not empty
var str = newValue.toString();
var arr = str.split(',');
for (var i = 0; i < arr.length; i++) {
if (!((arr[i] == '5fb4d3091bd51d505ab1646fe54bcbea') || (arr[i] == ""))) {
flg = 'true';
break;
}
}if (flg == 'true........
I tried joining them with my limited scripting ability as follows, but the count still increments despite the free item 5fb4 being selected (unless its the only item). I know its because its set to count all values in the catalog field, but how can I set the count to ignore 5fb4 if its selected.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var str = newValue.toString();
var arr = str.split(',');
for (var i = 0; i < arr.length; i++) {
if (!(arr[i] == '5fb4d3091bd51d505ab1646fe54bcbea')) {
value = g_form.getValue('catalogue');
len = value.split(',').length;
g_form.setValue('count', len);
}
}
}
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 01:50 AM
Managed to solve it with the following:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var a = '0';
var str = newValue.toString();
var arr = str.split(',');
for (var i = 0; i < arr.length; i++) {
if (arr[i] == '5fb4d3091bd51d505ab1646fe54bcbea') {
a = '1';
}
value = g_form.getValue('catalogue');
len = value.split(',').length;
g_form.setValue('count', (len-a));
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 01:50 AM
Managed to solve it with the following:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var a = '0';
var str = newValue.toString();
var arr = str.split(',');
for (var i = 0; i < arr.length; i++) {
if (arr[i] == '5fb4d3091bd51d505ab1646fe54bcbea') {
a = '1';
}
value = g_form.getValue('catalogue');
len = value.split(',').length;
g_form.setValue('count', (len-a));
}
}