Hello @torqueing,
Our plugin is not Excel, and you cannot use the same structures. For example, you cannot compare the fieldname8 with the choices’ texts, in the equations only are used the values. So, the correct equation would be:
(function(){
if(fieldname8 == 2879.17 && 2879.17 < fieldname7) return 2879.17;
if(fieldname8 == 2879.17 && fieldname7 < 2879.17) return fieldname7;
if(fieldname8 == 3629.17 && 3629.17 < fieldname7) return 3629.17;
return fieldname7;
})()
If you prefer to use the “IF” and “AND” operations distributed with the plugin, the equation would be:
IF(AND(fieldname8 == 2879.17, 2879.17 < fieldname7), 2879.17, IF(AND(fieldname8 == 2879.17, fieldname7 < 2879.17), fieldname7, IF(AND(fieldname8 == 3629.17 && 3629.17 < fieldname7), 3629.17,fieldname7)))
Actually, I prefer a more optimized implementation, all your equation is reduced to:
MIN(fieldname8,fieldname7)
Best regards.
Thankyou. You, my good man, are a genius 🙂
If I could give you more than 5 stars I would
Although I’m having a different problem I think it’s in the same ballpark wrt syntax.
This just doesn’t seem to work:
(function(){
if(fieldname7 < 1083.30) return 0 ;
}
else if(fieldname7 > 1083.30 && fieldname7 < 1614.33) {
1001 * 0.005 + fieldname7 -1001 *002 ;
}
else { return 7 ;
})()
-
This reply was modified 8 years, 2 months ago by
torqueing.
Hello @torqueing,
The number of symbols: “{” and “}” is incorrect, furthermore you are not using the “return” statements as should. The correct one is:
(function(){
if(fieldname7 < 1083.30){ return 0 ;}
else if(1083.30 <= fieldname7 && fieldname7 < 1614.33) { return 1001*0.005+fieldname7-1001*002 ;}
else { return 7;}
})()
or simply:
(function(){
if(fieldname7 < 1083.30) return 0 ;
if(1083.30 <= fieldname7 && fieldname7 < 1614.33) return 1001*0.005+fieldname7-1001*002;
return 7;
})()
Best regards.
Thanks again. I’ve never learned javascript so I’m trying to learn it through your examples and this on w3c schools
if (time < 10) {
greeting = "Good morning";
} else if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
hahaha 🙂
Hello,
Yes, but into a function structure you should use the “return” statement to return the result, for example, assuming that in your piece of code the time variable corresponds to the fieldname1 field, the equation would be:
(function(){
var greeting = "Good evening";
if (fieldname1 < 10) {
greeting = "Good morning";
} else if (fieldname1 < 20) {
greeting = "Good day";
}
return greeting;
})()
As you can see the equation is even simpler than the original code because the last “else” is unnecessary.
Best regards.