Skip to main content
first.officer
Inspiring
December 8, 2024
Answered

Checkboxes, export values and failure to clear these values when summed....

  • December 8, 2024
  • 1 reply
  • 548 views

Hi all,

I have a problem when using the script below, in a drop-down menu;

 

this.resetForm([“CheckboxA”, “CheckboxB”,” CheckboxC”]);

 

When the above script is used as part of some custom calculation script in a dropdown menu, the idea is that when the user makes a selection from one of the dropdown menu items, the script executes and ‘unchecks/de-selects/turns to OFF’ - any previous check-box selections that have been made. This works fine, and the 3 boxes do indeed become de-selected/unchecked/OFF.

 

The issue is that alongside having an export (numerical) value assigned to each of the three checkboxes, and that are calculated in another field (“SumTotal”) depending on the selections made, I also have some ‘Mouse Up’ script in each check-box, and that also exports in each case, further (numerical) values based on the check-box selections, to the respective fields shown below;

 

Checkbox A

if (event.target.value!="Off") this.getField("ExportValue1").value = -1
else this.getField("ExportValue1").value = 0;

 

Checkbox B

if (event.target.value!="Off") this.getField("ExportValue2").value =2
else this.getField("ExportValue2").value = 0;

 

Checkbox C

if (event.target.value!="Off") this.getField("ExportValue3").value = -4
else this.getField("ExportValue3").value = 0;


The three values (above) are then added (‘+’) together in another field called “ExportValueTotal”.

The issue is thus – when using the (reset) script shown at the very beginning of this topic, the check-box selections are ‘unchecked/de-selected/turned to OFF’, the field that sums the check-box assigned export values (“SumTotal”) goes to ZERO as expected, but despite the check-boxes being de-selected by this reset script – the ‘Mouse Up’ exported values as summed are still present in the “ExportValueTotal” despite no check-box selection now being present (i.e – no ‘tick’ and therefore an expectation that it should show ZERO as a value also). Of note, the reset still leaves values in the “ExportValue1”, “ExportValue2” & “ExportValue3” fields, hence the summed value in the “ExportValueTotal” field is actually summing the values correctly.

 

I have checked the field calculation order, and this is correct, so no issue there – the issue seems to be trying to force the values assigned in the “ExportValue” fields to be cleared – any way of doing this?.

 

Thanks for looking….

This topic has been closed for replies.
Correct answer Nesa Nurani

'else' part in checkbox does nothing since you use reset form, instead use script in each "ExportValue" fields to add value if checkbox is checked/unchecked, something like this:
if(this.getField("Checkbox A").valueAsString != "Off")

event.value = -1;

else

event.value = 0;

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
December 8, 2024

'else' part in checkbox does nothing since you use reset form, instead use script in each "ExportValue" fields to add value if checkbox is checked/unchecked, something like this:
if(this.getField("Checkbox A").valueAsString != "Off")

event.value = -1;

else

event.value = 0;

first.officer
Inspiring
December 8, 2024

As always, thanks Nesa - perfect!.