• Resolved chadtesting

    (@chadtesting)


    Hi there,

    I have a calculated field set up with the following code

    (function(){
    var prereqs = [fieldname70,fieldname312,fieldname316,fieldname320,fieldname324,fieldname308],
    prereqs;
    if fieldname70.val() != 'ENG4U' prereqs = "ENG4U needed for this program.";
    else prereqs = "Pre-requisites achieved";
    return prereqs;
    })()

    The calculated field is not outputting as expected. Could someone please help? Thank you.

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

    (@codepeople)

    Hello,

    There are multiple errors in your code:

    First, you don’t need call the val() for the fieldname70, because the plugin replace the fields’ names by their values in the equations.

    Second, in javascript the conditional statement “if” requires the conditions be closed into parentheses.

    Third, you are defining two times the “prereqs” variable in the same scope, generating a parser error.

    Fourth, you are assigning a value to the “prereqs” variable, and are not using the values in the initialization, so, you don’t need assign the initial array.

    Your equation should be edited as follows:

    (function(){
    if (fieldname70 != 'ENG4U') return "ENG4U needed for this program.";
    return "Pre-requisites achieved";
    })()

    or even simpler, using the “IF” operation implemented by the plugin (do not confuse with the conditional statement “if” of javascript) :

    IF(fieldname70 != 'ENG4U', 'ENG4U needed for this program.', 'Pre-requisites achieved')

    Best regards.

    Thread Starter chadtesting

    (@chadtesting)

    I suck. Thank you, works perfectly as usual.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help with if statement’ is closed to new replies.