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.
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?
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.
Thanks for the help, it worked perfectly!!
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’;
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.
Thank you for the help.
it works perfectly now!!