ken_s2007 Posted August 22, 2008 Posted August 22, 2008 Is there a direct way to, outside of field validation, test if a string is a member of a value list? I started looking at using ValueListItems in a calculation, but I didn't figure out a way to pull it off. Thanks, Ken
comment Posted August 22, 2008 Posted August 22, 2008 Try: not IsEmpty ( FilterValues ( string ; ValueListItems ( Get (FileName) ; "YourValueList" ) ) )
ken_s2007 Posted August 23, 2008 Author Posted August 23, 2008 That is excellent! It seems the "get" part is not needed, at least not as I tested the implementation: not IsEmpty ( FilterValues ( string ; ValueListItems ( "YourFileName" ; "YourValueList" ) ) ) Thank you so very much. Ken
LaRetta Posted August 24, 2008 Posted August 24, 2008 It seems the "get" part is not needed No, the "get" part is not needed at all. You can hardcode your file name within the calculation as you've indicated. But it will break if you ever change that file name ... surprise!! The reason for using Get ( FileName ) here is for protection and it should be used every time you find yourself in this situation. LaRetta
comment Posted August 24, 2008 Posted August 24, 2008 It will also break if you change the valuelist name ... Although you can protect yourself by hard-coding the valuelist ID instead, and calculating the name from that.
Fenton Posted August 24, 2008 Posted August 24, 2008 That's a great idea comment. I made a little file to illustrate. The IDs are permanently assigned. But they (and the Value List names) are returned in the last custom order of the value lists (the other sorts, by name, etc., don't make any difference; apparently FileMaker only stores the custom sort). So you could break a simple "get name by ID" if the custom order of the value lists was altered. Since they are returned the same order, you just need to get the value position of the ID of Value List you want, and use that to grab the name; which can then be used to get the ValueListItems (Get(FileName), "value list name"). I used a custom function to get the position of the value. It would also be done "manually", but I'm lazy; everyone on this thread has Advanced -] Another little glitch is that it seems to return the 1st Value List on failure (position = 0). So you want to check for that. So, is this what you meant? Or is there a simpler method? VLI_by_ID.fp7.zip
comment Posted August 24, 2008 Posted August 24, 2008 Thanks, but I stole the idea from Fabrice. As for implementation, I believe it could be a bit simpler. For example, to get the name of a valuelist with the ID of 4: Let ( ID = 4 ; GetValue ( ValueListNames ( Get (FileName) ) ; ValueCount ( Left ( ValueListIDs ( Get (FileName) ) ; Position ( ¶ & ValueListIDs ( Get (FileName) ) & ¶ ; ¶ & ID & ¶ ; 1 ; 1 ) ) ) ) ) This could be easily turned into a custom function with ID as the parameter. And the complementing calculation (get ID from name) Let ( VLname = "MyValueList" ; GetValue ( ValueListIDs ( Get (FileName) ) ; ValueCount ( Left ( ValueListNames ( Get (FileName) ) ; Position ( ¶ & ValueListNames ( Get (FileName) ) & ¶ ; ¶ & VLName & ¶ ; 1 ; 1 ) ) ) ) ) Fabrice has written a more generic custom function that converts ID to name and vice-versa for fields, layouts, scripts, tables and valuelists alike: http://www.briandunning.com/cf/858 Although it looks very complex, it's actually not so difficult once you rewrite it in the syntax of mere mortals. :ooo:
LaRetta Posted August 24, 2008 Posted August 24, 2008 Consider the stolen idea's variation restolen. Thanks! :wink2:
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now