Copy link to clipboard
Copied
I am currently using the below formula for subtraction. However, if "FieldB.0" is empty, I do not want the script to run. When ever "FieldA.0" is filled in, it is still returning the value. I know I need to use an "if" in the script but I do not know how to do that.
var v1 = getField("FieldA.0").value;
var v2 = getField("FieldB.0").value;
event.value=v1-v2;
Copy link to clipboard
Copied
Use this:
var v1 = getField("FieldA.0").valueAsString;
var v2 = getField("FieldB.0").valueAsString;
if (v1=="" || v2=="") event.value = "";
else event.value=Number(v1)-Number(v2);
Copy link to clipboard
Copied
Use this:
var v1 = getField("FieldA.0").valueAsString;
var v2 = getField("FieldB.0").valueAsString;
if (v1=="" || v2=="") event.value = "";
else event.value=Number(v1)-Number(v2);
Copy link to clipboard
Copied
Perfect, thank you.
Copy link to clipboard
Copied
Hi it just worked Fine, but there is a problem, i want the subtraction as if Field1 - Field2 = Ans, but i want to add +1 in Answer if the value is given, and if the value is not given then answer must be zero plz guide me. for example 401 - 500 = 100 (Answer should be this) but if the fields are empty then answer must be the zero. picture is attached.
Copy link to clipboard
Copied
Change the last two lines to:
if (v1=="" || v2=="") event.value = 0;
else event.value=(Number(v1)-Number(v2))+1;
Copy link to clipboard
Copied
I have applied the following formula but i want that if the given data is zero then the result in total shall also be zero (0) Rest of the things are okay.
Here is the formula which i applied:
var v1 = getField("field2.0").valueAsString; var v2 = getField("field1.0").valueAsString; if (v1=="" || v2=="") event.value = 0; else event.value=(Number(v1)-Number(v2))+1;
Copy link to clipboard
Copied
Change the third line to:
if (v1=="" || v2=="" || (v1+v2)==0) event.value = 0;
Copy link to clipboard
Copied
Thank u so much God bless u, Thanks alot .

