rkury14 Posted April 6, 2016 Share Posted April 6, 2016 Support, I need help with this rule. if (Field("Video_Level") == "" && Field("Data_Level") == "" && Field("Phone_Level") == "") { return ""; } else return Field("Video_Level") + ", " + Field("Data_Level") + " and " + Field("Phone_Level"); I need to add to it so the Comma "," and the "and" disappear when the other items are not there. For example, This is what it looks like with all three: Video Level, Data Level and Phone Level. But if there are only Video and Data levels I need the comma to not show and the "and" placed in between. And if only Video level is there for the comma & " and" to not show and so on. Thanks Rayed Quote Link to comment Share on other sites More sharing options...
tou Posted April 6, 2016 Share Posted April 6, 2016 (edited) without too much programming....you can try the following in the text editor...but it looks like it's a little more complicated than that.... something like this would work..... var token = 0 var parser1 = "" var parser2 = "" if (Len(Trim(Field("Video_Level")))>0) { token = token+1 } if (Len(Trim(Field("Data_Level")))>0) { token = token+1 } if (Len(Trim(Field("Phone_Level")))>0) { token = token+1 } if (token=2) { parser1 = " and " } if (token=3) { parser1 = ", " parser2 = " and " } return Field("Video_Level)+parser1+Field("Data_Level")+parser2+field("Movie_Level") Edited April 6, 2016 by tou Quote Link to comment Share on other sites More sharing options...
rkury14 Posted April 6, 2016 Author Share Posted April 6, 2016 Thanks Tou, but the separators "," & "and" still show up when I need them to disappear. Quote Link to comment Share on other sites More sharing options...
tou Posted April 6, 2016 Share Posted April 6, 2016 I was thinking when all three variables was empty...sorry. I did update my post with a javascript that I think will work. I'm sure there's other ways of doing it. Good luck! Quote Link to comment Share on other sites More sharing options...
step Posted April 6, 2016 Share Posted April 6, 2016 You can do this with the code that I posted http://forums.pti.com/showpost.php?p=18408&postcount=4 in the thread that has basically the same topic. Quote Link to comment Share on other sites More sharing options...
jwhittaker Posted April 6, 2016 Share Posted April 6, 2016 I'm a hack so I know there is a more efficient way but try this: if ((Field("Video_Level") == "") && (Field("Data_Level") == "") && (Field("Phone_Level") == "")) { return ""; } else if ((Field("Video_Level") != "") && (Field("Data_Level") != "") && (Field("Phone_Level") != "")) { return Field("Video_Level") + ", " + Field("Data_Level") + " and " + Field("Phone_Level"); } else if (Field("Video_Level") != "") { if ((Field("Data_Level") != "") || (Field("Phone_Level") != "")) return Field("Video_Level") + " and " + Field("Data_Level") + Field("Phone_Level"); } else { if ((Field("Data_Level") != "") && (Field("Phone_Level") != "")) return Field("Data_Level") + " and " + Field("Phone_Level"); else return Field("Data_Level") + Field("Phone_Level"); } Quote Link to comment Share on other sites More sharing options...
tou Posted April 6, 2016 Share Posted April 6, 2016 I tested the following and it works, but not dynamic like step's... var string1 = "Something" var string2 = "" //var string2 = "Something2" var string3 = "" //var string3 = "Something3" var token = 0 if (Trim(string1)!="") { token = token+1 } if (Trim(string2)!="") { token = token+1 } if (Trim(string3)!="") { token = token+1 } var parser1 = "" var parser2 = "" if (token==2) { parser1 = " and " parser2 = "" } if (token==3) { parser1 = ", " parser2 = " and " } return string1+parser1+string2+parser2+string3 Quote Link to comment Share on other sites More sharing options...
rkury14 Posted April 6, 2016 Author Share Posted April 6, 2016 Tou, sorry, it's not working for me. I am still a beginner. I tried putting my linked fields in the "something" area, but it is not linking to my list. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted April 6, 2016 Share Posted April 6, 2016 You can do this with the code that I posted http://forums.pti.com/showpost.php?p=18408&postcount=4 in the thread that has basically the same topic. Yes, basically this same question has been answered many times on the forum. To specifically apply Step's solution to your job, try this: var items = [Field("Video_Level"), Field("Data_Level"), Field("Phone_Level")].filter(String); var last = items.pop(); return [items.join(", "), last].filter(String).join(" and "); If you adapt my answer here, you can do it as a one-liner: return [Field("Video_Level"), Field("Data_Level"), Field("Phone_Level")].filter(String).join(", ").replace(/^(.*)(, )(.*?)$/, "$1 and $3"); Add a comma before " and" in either case to use the Oxford Comma. Quote Link to comment Share on other sites More sharing options...
rkury14 Posted April 6, 2016 Author Share Posted April 6, 2016 Dan, Your rule worked!! Much appreciated. :-) Default Re: multiple names rule Try this: Code: var names = [Field("Name1"), Field("Name2"), Field("Name3"), Field("Name4")]; return names.filter(Boolean).join(", ").replace(/^(.*)(, )(.*?)$/, "$1, and $3"); If you don't want the serial comma before the word "and", remove it after the "$1" above. Quote Link to comment Share on other sites More sharing options...
tou Posted April 7, 2016 Share Posted April 7, 2016 Tou, sorry, it's not working for me. I am still a beginner. I tried putting my linked fields in the "something" area, but it is not linking to my list. Glad you got it to work. 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.