Jump to content

Variable Graphic based on field true or false


Danovh

Recommended Posts

I need a rule for a variable graphic based on fields true or false.

If field name 3 is true, then place image 3,

if field name 2 is true and field name 3 is false, the place image 2,

if field name 3 is false and field name 2 is false, then place image 1.

I made a rule with the rule wizard using that logic, but just get image 1.

What am I doing wrong.

 

if (Field("ITEM 3 NAME") == String("true"))

{

return Resource("printer_list3.eps");

}

if ((Field("ITEM 2 NAME") == String("true")) && (Field("ITEM 3 NAME") == String("false")))

{

return Resource("printer_list2.eps");

}

if ((Field("ITEM 3 NAME") == String("false")) && (Field("ITEM 2 NAME") == String("false")))

{

return Resource("printer_list1.eps");

}

else

{

return Resource("printer_list1.eps");

}

return "";

Link to comment
Share on other sites

I believe the third IF statement and the following ELSE statement are the source of your problems. When the code is called, the last valid return statement returns it's value, and in the code above, the ELSE statement is valid for both of the first two IF loops so the value they would return is overridden by the ELSE result.

 

Instead your code should be cleaned up to only have one option available for every possibility. Perhaps like so:

if (Field("ITEM 3 NAME") == "true") {
   return Resource("printer_list3.eps");
   }
else if (Field("ITEM 2 NAME") == "true" && Field("ITEM 3 NAME") == "false") {
   return Resource("printer_list2.eps");
   }
else return Resource("printer_list1.eps");

Of course, if all three names (assuming there is also a field "ITEM 1 NAME") are false, the printer_list1.eps resource would still be returned. If this is the case, the code should be revised further:

if (Field("ITEM 3 NAME") == "true") {
   return Resource("printer_list3.eps");
   }
else if (Field("ITEM 2 NAME") == "true") {
   return Resource("printer_list2.eps");
   }
else if (Field("ITEM 1 NAME") == "true") {
   return Resource("printer_list1.eps");
   }
else return NullResource();

In this scenario, the printer_list resource returned matches the number of the field that has a value of "true". Of course, if two or more of your fields both contain "true" in a given record, this rule would return the graphic associated with the field with the lowest number containing a "true" string. To deal with the possibility that a record might (erroneously) contain a "true" value for more than one field, you would need to test all three fields in each IF loop:

if (Field("ITEM 3 NAME") == "true" && Field("ITEM 2 NAME") == "false" && Field("ITEM 1 NAME") == "false") {
   return Resource("printer_list3.eps");
   }
else if (Field("ITEM 3 NAME") == "false" && Field("ITEM 2 NAME") == "true" && Field("ITEM 1 NAME") == "false") {
   return Resource("printer_list2.eps");
   }
else if (Field("ITEM 3 NAME") == "false" && Field("ITEM 2 NAME") == "false" && Field("ITEM 1 NAME") == "true") {
   return Resource("printer_list1.eps");
   }
else return NullResource();

In this script, a resource is only returned when one (and only one) field contains a "true" value. If no fields are true, or more than one field is true, nothing is returned.

Link to comment
Share on other sites

Thank you for your quick reply.

If item 3 is true, then item 1 & item 2 are true.

This is based on customer orders.

They could of ordered 1 item, but if they ordered 3 then of course there is items 1 & 2.

 

I solved this by making 3 identical graphic holes, the 3rd one on top and the 1st one on bottom, and made rules for each to suppress if the item field is false.

this seems to be working fine.

 

I will play around with your rules to see what I get.

 

Thanks again.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...