mstanton Posted August 10, 2009 Share Posted August 10, 2009 Hello, I am wondering if there is a rule to say "If the <next field> has any value, then return a specific value." I want a specific value returned if the next field, whatever that may be, has text in it. For example, in a single line there are 6 fields and a bullet separating some of them: «P1 Type» «Phone1» • «P2 Type» «Phone2» • «P3 Type» «Phone3» If there is no value for «P2 Type» or «P3 Type» I don't want the bullets in front of them to appear either. It would be nice to have one rule that I could place anywhere within the line and it would apply the value based on the next field, rather than creating crazy conditional statements. Any suggestions? Link to comment Share on other sites More sharing options...
rpaterick Posted August 10, 2009 Share Posted August 10, 2009 Should be able to use this code below for each individual parts. Below is the fax example. [size=4][color=Red]if (Field("fax") == "") return ""; else return" FAX " + Field("fax") + " ·";[/color][/size] Link to comment Share on other sites More sharing options...
mstanton Posted August 10, 2009 Author Share Posted August 10, 2009 I have done that already but I'm looking for a more universal solution so I don't have to make a separate rule for 50 different fields. Thanks, though. Link to comment Share on other sites More sharing options...
Hadrian Posted August 10, 2009 Share Posted August 10, 2009 You could use this to examine the fields that follow your "P1 Type" but it sounds like you need to make an array from the fields. The code below needs to have "P1 Type" populated to work. If you do not need that then take the second condition out. You need to have the code look through 50 fields to populate it? Sounds like you are making a directory of sorts, correct? var dirOut = ""; var bullet = " "; if (Field("P1 Type")!= "") { dirOut += Field("P1 Type") + " " + Field("Phone1"); } if (Field("P2 Type") != "") { if (dirOut != "") { dirOut += bullet + Field("P2 Type") + " " + Field("Phone2"); } } if (Field("P3 Type") != "") { if (dirOut != "") { dirOut += bullet + Field("P3 Type") + " " + Field("Phone3"); } } return dirOut; Link to comment Share on other sites More sharing options...
esmith Posted August 11, 2009 Share Posted August 11, 2009 I have done that already but I'm looking for a more universal solution so I don't have to make a separate rule for 50 different fields. Thanks, though. How about something like this: //totalFields should match maximum possible fields with data var totalFields = 50; var Data = ""; for (i=1; i<=totalFields; i++) { currType = "P" + i + " Type"; currPhone = "Phone" + i; if (Field(currType) != "") { Data += " • " + Field(currType) + " " + Field(currPhone); } } return Data; Link to comment Share on other sites More sharing options...
esmith Posted August 11, 2009 Share Posted August 11, 2009 Oops! In my above code, you will also get a bullet preceding the first TYPE and PHONE. the easiest solution is to replace the return line above with: return Data.replace(" • ", ""); Link to comment Share on other sites More sharing options...
mstanton Posted August 11, 2009 Author Share Posted August 11, 2009 Thanks! I'll give that a try. Link to comment Share on other sites More sharing options...
mstanton Posted August 11, 2009 Author Share Posted August 11, 2009 Eric, I tried your code and it worked pretty good. Unfortunately if someone accidentally enters a value for P1 (or 2 or 3) Type but not for Phone1, the bullet still shows up. Is there a way to change this so that the bullet will only appear if there is a value for either P Type and Phone, OR just Phone, but NOT just P Type (I already have a rule that suppresses P Type if Phone has no value)? Thanks! Link to comment Share on other sites More sharing options...
esmith Posted August 11, 2009 Share Posted August 11, 2009 Is there a way to change this so that the bullet will only appear if there is a value for either P Type and Phone, OR just Phone The way this reads, you could just test for data in PHONE since it is required in either test. If so, then replace: if (Field(currType) != "") { with if (Field(currPhone) != "") { If instead you want to test for content in both TYPE and PHONE then change the former line to if ((Field(currType) != "") && (Field(currPhone) != "")) { instead. HTH. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.