• Resolved borgesleti

    (@borgesleti)


    First of all, I would like to thank you for this great plugin!

    I’m wondering whether I can make a conditional operation with a predefined end value.
    for example: if fieldx>=100 or fieldx <=500, so return fieldx == 20
    but if fieldx <=500 or fieldx <=1000, so its return fieldx == 50

    I don’t know how to do this operation or if this is possible.

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

    (@codepeople)

    Hello @borgesleti

    Thank you very much for using our plugin.

    I’m sorry, but your conditions don’t have much sense because you are repeating the same condition to return different values:

    fieldx <=500 returns 20

    fieldx <=500 returns 50

    So, I will try to describe the process with a hypothetical example.

    Assuming you have the number field feildname1, and you want to return 20 if the fieldname1 is in the range 100<fieldname1 and fieldname2<500, and 50 if fieldname1<=100 or 500<=fieldname1.

    In this hypothetical case, the equation associated with the calculated field could be implemented as follows:

    Using the function structure and the if conditional statement:

    (function(){
    if(100<fieldname1 && fieldname1<500) return 20;
    else return 50;
    })()

    The same equation by using the IF conditional operation (Javascript is a case sensitive language, do not confuse the IF operation with the if conditional statement):

    IF(100<fieldname1 && fieldname1<500, 20, 50)

    Finally, the same equation but this time using the javascript ternary operator:

    (100<fieldname1 && fieldname1<500) ? 20 : 50

    The three previous equations are equivalent and return the same result.

    Best regards.

    Thread Starter borgesleti

    (@borgesleti)

    thanks for the support, it worked as explained to me.
    But i have one last question

    Is it possible to have a conditional that returns a result in Text? For example:

    If fieldname1>=200 it shows me the text “Positive Result”, Else not it shows me the text “Median Result”

    But

    If fieldname1<100 it shows me the text “Negative Result”, Else not it shows me the text “Median Result”

    It’s possible? Or how to do?

    Plugin Author codepeople

    (@codepeople)

    Hello @borgesleti

    Yes, that’s possible. You can nest IF operations as follows:

    IF(fieldname1>=200, 'Positive Result', IF(fieldname1<100, 'Negative Result', 'Median Result'))

    Best regards.

    Thread Starter borgesleti

    (@borgesleti)

    Thanks for the help, it worked perfectly!!

    Thread Starter borgesleti

    (@borgesleti)

    Could i add this in a function for the text color to change too?
    for example:

    if(fieldname1>200) result = ‘Positive Result’; color = ‘Green’;
    if(fieldname1>=100) result = ‘Median Result’; color = ‘orange’;
    if(fieldname1<100) result = ‘Negative Result’; color = ‘red’;

    Plugin Author codepeople

    (@codepeople)

    Hello @borgesleti

    Yes, that’s possible, but the equation is little more complex. If the calculated field is the feildname123, the equation would be:

    (function(){
    var field = getField(123).jQueryRef().find('input'),
    color, result;
    if(fieldname1>200){ result = 'Positive Result'; color = 'Green';}
    else if(fieldname1>=100){ result = 'Median Result'; color = 'orange';}
    else{ result = 'Negative Result'; color = 'red';}
    
    field.css('color', color);
    return result;
    })()

    The getField operation receives the number component in the field’s name and returns its object representation.

    Best regards.

    Thread Starter borgesleti

    (@borgesleti)

    Thank you for the help.
    it works perfectly now!!

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

The topic ‘conditional operations’ is closed to new replies.