• Resolved Joshua Alexander

    (@jalexanderphd)


    Example solving for if(field 1 is > 2) and if (field 2 is > 3) then that field = a certain number I see how to do it once but haven’t seen how to do it with more than one need to have 2 variables.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    In javascript the logical operators that represent the “AND” and “OR”, are the double symbols: “&&” and “||” respectively. So, if you want to return a number, for example: 1234, if the values of fields: fieldname1, and fieldname2 are 2 and 3, respectively, and the number 4321 in other cases, a possible equation would be:

    (function(){
    if(fieldname1>2 && fieldname3>3) return 1234;
    else return 4321;
    })()

    For simple equations like the previous one, you can use directly the ternary operator of javascript:

    (fieldname1>2 && fieldname3>3) ? 1234 : 4321

    or the “IF” and “AND” operations distributed with the plugin:

    IF(AND(fieldname1>2, fieldname3>3), 1234, 4321)

    Note that javascript is a case sensitive language, please, do not confuse the conditional statement “if” in javascript, with the “IF” operation distributed with the plugin.

    More information in the following link:

    https://cff.dwbooster.com/documentation#conditions-module

    Best regards.

    Thread Starter Joshua Alexander

    (@jalexanderphd)

    Is there a place in the plugin for it or just add it to functions.php

    Plugin Author codepeople

    (@codepeople)

    Hello @jalexanderphd,

    You simply should insert a “Calculated Field” in the form, and enter the equation through the textarea “Set Equation” in its properties (the properties are displayed in the left bar)

    Properties of calculated fields

    Best regards.

    Thread Starter Joshua Alexander

    (@jalexanderphd)

    So we add the if statements to the equation block?

    Plugin Author codepeople

    (@codepeople)

    Hello @jalexanderphd,

    Yes, you are right, enter the equation’s code directly into the “Set Equation” property, but remember, depending on your equation’s structure you might need to implement it with the function structure, using “return” statements:

    (function(){
    if(fieldname1>2 && fieldname3>3) return 1234;
    else return 4321;
    })()

    or if the equation is simple, use the “IF” operation or the ternary javascript operator directly:

    IF(AND(fieldname1>2, fieldname3>3), 1234, 4321)

    Best regards.

    Thread Starter Joshua Alexander

    (@jalexanderphd)

    Ok actually found out don’t need it that complex.
    IF(AND(fieldname5>2<=30, fieldname5<=29, fieldname5<=13, fieldname5<=6), 22, 21.34, 20, 16.66)

    Works for 22 and 21.34 am I missing something no change when I type anything over 14. But works for 1-13

    Plugin Author codepeople

    (@codepeople)

    Hello @jalexanderphd,

    Please, check the documentation of the operations (https://cff.dwbooster.com/documentation#conditions-module). The “IF” operation only accepts three parameters, the additional parameters are ignored:

    IF(condition, result if condition true, result if condition false)

    but you can nesting “IF” operations, as follows:

    IF(condition, result if condition true, IF(second condition, result if second condition true, result if second condition false))

    Best regards.

    Thread Starter Joshua Alexander

    (@jalexanderphd)

    How would I add a forth tried this one didn’t work.+

    Thread Starter Joshua Alexander

    (@jalexanderphd)

    IF(fieldname5<=6, 24, IF(fieldname5<=13, 21.34, IF(fieldname5<=29, 20, 16.66)) is what I have based on the last one

    Plugin Author codepeople

    (@codepeople)

    Hello @jalexanderphd,

    You’ve forgotten a closing parenthesis:

    IF(fieldname5<=6, 24, IF(fieldname5<=13, 21.34, IF(fieldname5<=29, 20, 16.66)))

    Best regards.

    Thread Starter Joshua Alexander

    (@jalexanderphd)

    Nevermind figured out a way to force it to work. Thanks for the help it steered me in the correct direction.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Multiple conditions’ is closed to new replies.