Copy link to clipboard
Copied
I'm sorry for not taking a more research based approach but this is a side project for my job that I can't put too much time into - I apologize if some of these questions are just very silly.
My form is meant to use if/then calculations to return information based on data from 240ish fields that may or may not end up with data in them. The fields will be populated with information pulled from another program and are broken into three types of field "__.AC1/2/3" "__.EX1/2/3" AND "__.FN1/2/3" the idea being that AC1/EX1/FN1 will end up being populated with the information specific to one object.
The code I'm currently working on is below:
var a = this.getField("FLB.EX1").value
var b = this.getField("FLB.EX2").value
var c = this.getField("FLB.EX3").value
var nr = event.value
var n1 = getField("FLB.FN1").valueAsString
var n2 = getField("FLB.FN2").valueAsString
var n3 = getField("FLB.FN3").valueAsString
var em1 = getField("EM.EX1").value
var em2 = getField("EM.EX2").value
var em3 = getField("EM.EX3").value
if(em1 >= .3 || em2 >= .3 || em3 >= .3)
{if(a > b && a > c)
{nr = n1} else
if(b > c)
{nr = n2} else {nr = n3}}
My questions at this point:
1) if I declare var a = x within the custom calc for a field is that going to define "a" for all calculations in all text fields, or is it specific to that field?
2) sometimes it seems like custom calc won't work if I have a long string of conditions {if x {if y {if z {do this} else if this {}}else this}else this} - is there a limit to that sort've formula?
3) the above SEEMS like a super simple version of some other code that IS working within my document... but it isn't populating FLB.FN2 in the result field, and I can't for the life of me figure out why.
Any input on the above would be deeply appreciated.
UPDATE:
I changed the code to read:
if(this.getField("EM.EX1").value >= .3 || this.getField("EM.EX2").value >= .3 || this.getField("EM.EX3").value >= .3)
{if(this.getField("FLB.EX1").value > this.getField("FLB.EX2").value && this.getField("FLB.EX1").value > this.getField("FLB.EX3").value) {event.value = getField("FLB.FN1").valueAsString} else
if(this.getField("FLB.EX2").value > this.getField("FLB.EX3").value) {event.value = getField("FLB.FN2").value} else
{event.value = getField("FLB.FN3").valueAsString}}
that's working and the above was not. No idea why? Am I declaring or referencing variables incorrectly or is there some other syntax error?
Yes. The variables in your code are a copy of the fields' values, not a
reference to them.
Copy link to clipboard
Copied
I don't see the character ';' at the end of your declarations.
Copy link to clipboard
Copied
do you mind writing it in to the above code, I'm not sure what you're suggesting (sorry - total novice)
Copy link to clipboard
Copied
I mean the var declarations.
Copy link to clipboard
Copied
Ugh - it worked for the first half of my formula but isn't working anymore. Here is revised code:
var a = this.getField("FLB.EX1").value;
var b = this.getField("FLB.EX2").value;
var c = this.getField("FLB.EX3").value;
var nr = getField("RFLB").value;
var n1 = getField("FLB.FN1").valueAsString;
var n2 = getField("FLB.FN2").valueAsString;
var n3 = getField("FLB.FN3").valueAsString;
var em1 = getField("EM.EX1").value;
var em2 = getField("EM.EX2").value;
var em3 = getField("EM.EX3").value;
if (em1 >= .003 || em2 >= .003 || em3 >= .003)
{if (a >= .003 || b >= .003 || c >= .003)
{if(a > b & a > c)
{nr = n1} else
if(b > c)
{nr = n2} else
{nr = n3}
}
} else
if (a < b & a < c)
{nr = n1} else
if (b < c)
{nr = n2} else
{nr = n3}
any thoughts? Sorry to be a pest.
Copy link to clipboard
Copied
does somebody else keep marking that as correct? That code ISNT working and I have no idea why.
Copy link to clipboard
Copied
Check the console for errors.
Copy link to clipboard
Copied
A variable declared within a calculation script will only be available
there, yes.
Copy link to clipboard
Copied
Okay as a followup I've noticed that the following is happening. If I enter
getField("RLB").value = getField("LBFN1").valueAsString my field correctly populates with the data in LBFN1, but if I try
var rn = getField("RLB").value;
var n1 = getField("LBFN1").valueAsString;
rn = n1
the field will not populate. Is it possible that there's some issue with declaring variables in a calculation script?
Copy link to clipboard
Copied
Yes. The variables in your code are a copy of the fields' values, not a
reference to them.