Jump to content

If X, Y & X are Blank, then do this, else do that.


Diane

Recommended Posts

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");

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...