Skip to main content
Participant
September 6, 2017
Answered

compare text fields

  • September 6, 2017
  • 1 reply
  • 761 views

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?

This topic has been closed for replies.
Correct answer try67

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?


Yes. The variables in your code are a copy of the fields' values, not a

reference to them.

1 reply

Bernd Alheit
Community Expert
Community Expert
September 6, 2017

I don't see the character ';' at the end of your declarations.

Participant
September 6, 2017

do you mind writing it in to the above code, I'm not sure what you're suggesting (sorry - total novice)

Bernd Alheit
Community Expert
Community Expert
September 6, 2017

I mean the var declarations.