Diane Posted February 29, 2016 Share Posted February 29, 2016 We are trying to create a rule that basically says If Field “X” and Field “Y” and Field “Z” are empty return Resourse “Blank” else return Resource “YellowLine” We have tried this several ways and are not able to make it work. Here are 3 of the different ways we tried to write it… HELP!!! if(Field ("Name") != "" || Field("Phone") != "" || Field("Email") != "") return NullResource(<none>); else return Resource("YellowLine"); if (Field("Name") == "") if (Field("Phone") == "") if (Field("Email") == "") return Resource("Blank"); else return Resource("YellowLine"); if (Field("Name") == ""&&Field("Phone") == ""&&Field("Email") == ""); return Resource("Blank"); else return Resource("YellowLine"); Quote Link to comment Share on other sites More sharing options...
DSweet Posted March 1, 2016 Share Posted March 1, 2016 Hello Diane, Try this one...if ((Field("Name") == "") && (Field("Email") == "") && (Field("Phone") == "")) { return Resource("Blank"); } else { return Resource("YellowLine"); }I think you were a bit mixed up with the use of parenthesis. Quote Link to comment Share on other sites More sharing options...
Diane Posted March 1, 2016 Author Share Posted March 1, 2016 THANK YOU SOOOO MUCH! That worked:) Quote Link to comment Share on other sites More sharing options...
step Posted March 1, 2016 Share Posted March 1, 2016 Diane, I just wanted to note that your previous efforts weren't that far off. Here's why they didn't work, though: if(Field ("Name") != "" || Field("Phone") != "" || Field("Email") != "") return NullResource([color="Red"]<none>[/color]); else return Resource("YellowLine"); If you remove the "<none>" tag in the "NullResource" function, the above code will work perfectly. if (Field("Name") == "") if (Field("Phone") == "") if (Field("Email") == "") return Resource("Blank"); else return Resource("YellowLine"); There's actually nothing wrong with the above code but it's important to note that the way it's written is actually interpreted as a nested if statement. Like this: if (Field("Name") == "") { if (Field("Phone") == "") { if (Field("Email") == "") { return Resource("Blank"); } } } else { return Resource("YellowLine"); } if (Field("Name") == ""&&Field("Phone") == ""&&Field("Email") == "")[color="red"];[/color] return Resource("Blank"); else return Resource("YellowLine"); If you were to remove the semi-colon at the end of the if condition, the above code would work as well. The semi-colon is used to separate statements in JavaScript so that particular semi-colon is interrupting the if statement. Yet another way to write this is using the ternary operator: return (Field("Name") || Field("Phone") || Field("Email")) ? Resource("YellowLine") : Resource("Blank"); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted March 2, 2016 Share Posted March 2, 2016 Diane, I just wanted to note that your previous efforts weren't that far off. Here's why they didn't work, though: if(Field ("Name") != "" || Field("Phone") != "" || Field("Email") != "") return NullResource([color="Red"]<none>[/color]); else return Resource("YellowLine"); If you remove the "<none>" tag in the "NullResource" function, the above code will work perfectly. if (Field("Name") == "") if (Field("Phone") == "") if (Field("Email") == "") return Resource("Blank"); else return Resource("YellowLine"); There's actually nothing wrong with the above code but it's important to note that the way it's written is actually interpreted as a nested if statement. Like this: if (Field("Name") == "") { if (Field("Phone") == "") { if (Field("Email") == "") { return Resource("Blank"); } } } else { return Resource("YellowLine"); } You can also get rid of the "else" in those rules. If you return, then you immediately leave the rule and don't ever run any of the code past that return statement. Quote Link to comment Share on other sites More sharing options...
Diane Posted March 2, 2016 Author Share Posted March 2, 2016 Thank you Step! So good to know there are people out there to help!!!! Greatly appreciated! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.