Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Test is string is a member of a value list?

Featured Replies

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

Try:

not IsEmpty ( FilterValues ( string ; ValueListItems ( Get (FileName) ; "YourValueList" ) ) )

  • Author

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

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

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.

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

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:

Consider the stolen idea's variation restolen. Thanks! :wink2:

Yep, that idea is definitely a keeper. }:(

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.