• Resolved gordchan

    (@gordchan)


    In my calculated field, I mostly want to return a number, e.g. 10. But in some cases, I want to return a text message, e.g. “More than 10 months” or “Questionable”. In these exceptions, I want to be able to hide some fields.

    I tried to do that by using typeof to screen for strings in a function. But I found that “More than 10 months” would still be parsed as a number (10), while “Questionable” would be a string. Is this behaviour expected? Is there any way for me to screen for “More than 10 months”?

    Thank you.

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

    (@codepeople)

    Hello @gordchan

    Thank you very much for using our plugin. Yes, that’s possible. I’ll try to describe the process with a hypothetical example.

    Assuming you have the equation fieldname1+fieldname2, and you want to returns the numeric result for values lower than or equal to 10, and the text “More than 10 months” otherwise. Additionally, you want to disable the fields fieldname3 and fieldname4 if the result of the mathematical operation is over 10.

    You can implement this process from the equation as follows:

    (function(){
    var result = fieldname1+fieldname2;
    if(result <= 10){
       ACTIVATEFIELD(fieldname3|n);
       ACTIVATEFIELD(fieldname4|n);
       return result; 
    }
    
    IGNOREFIELD(fieldname3|n);
    IGNOREFIELD(fieldname4|n);
    return 'More than 10 months';
    })()

    Note the use of the |n modifier in fieldname3|n and fieldname4|n. The plugin replaces the field names in the equations by their respective values before evaluation to apply the mathematical operations (fieldname1+fieldname2). The |n modifier tells the plugin you are referring to the field’s name directly, not its value.

    Best regards.

    Thread Starter gordchan

    (@gordchan)

    Thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Text parsed as number’ is closed to new replies.