Copy link to clipboard
Copied
I would like help with the following please:
When 'New' is selected the calculated value of 'Total' must be overwritten with value '795', otherwise the values of 'V1', 'V2', 'V3', 'A1', 'A2', and so on must be added up to 'Total'.
I currently have place this script to the 'Total' field (tab Calculate, alternate calulated script), but keep getting errors when 'Damaged' is selected (possibly because the underlying options are not selected yet?):
var soort = this.getField("Soort").valueAsString;
if (soort=="New") { event.value = "795"; }
else if (soort=="Damaged")
{ var v1=this.getField("V1").value;
var v2=this.getField("V2").value;
var v3=this.getField("V3").value;
var v4=this.getField("V4").value; //and so on...
event.value = 0+v1+v2+v3+v4; }
Copy link to clipboard
Copied
Create hidden text field, in that field go to calculate tab and use "value is the" and pick all of your checkboxes that you want to calculate( v1-v4, a1-a4...etc)
then in total field use this code:
var sort = this.getField("Soort").valueAsString;
var hid = Number(this.getField("Hiddenfield").valueAsString);
if(sort == "New"){
event.value = "795";}
else if(sort == "Damaged"){
event.value = hid;}
Copy link to clipboard
Copied
Almost... The error message have dissappeared 🙂
Unfortunately at selecting the checkboxes, the values aren't calculated at once. So I get 'delayed' feedback, and therefore incorrect values within the field 'Total'.
For instance: Value of checkbox 'V1' = 17,40. On selection the value of 'Total' doesn't change. On de-selection thereafter the value of 'Total' changes to 17,40 ...
Copy link to clipboard
Copied
Go to field calculation order and make sure hidden field is above total field, that should fix delay.
Copy link to clipboard
Copied
What error messages does you get?
Copy link to clipboard
Copied
The entered value does not match the format of the field
Copy link to clipboard
Copied
This is most likely because you're using a number format that isn't acceptable for a script. You mentioned "17,40". If you want to enter it like that then you have to use the "1.234,56" option under Number in the field's Format tab, so that it would know you're using the comma as the decimal separator. If you don't do that it won't be able to convert this value to a number.
Copy link to clipboard
Copied
Thank you Bernd. Just checked, but this is already the case. Maybe it's because the value comes from a 'checkbox', in which I can't define the format of the exported value?
Copy link to clipboard
Copied
Set the format of the total field to "None". What can you see as result?
Copy link to clipboard
Copied
Good thinking. Something strange is happening now:
The value of 'Total' is now e.g. 017,40OffOff17,40
Off appears for the checkboxes which are not selected, 17,40 for the checked ones.
Copy link to clipboard
Copied
Change the export values to "17.4", instead of "17,4", and change the last line of code to:
event.value = 0;
if (v1!="Off") event.value+=Number(v1);
if (v2!="Off") event.value+=Number(v2);
etc.