Function overview
Prototype
FM_Name_ID (
_Name_ID; _TLFSV; _fileName; _layoutName )
Parameters
_Name_ID a database element name or ID
_TLFSV the element type (
_fileName for current file, just send an empty (
_layoutName only if _TLFSV is
Description
Tags:
value list table occurrence script layout ID hard-coding field debug
Hard-coding a field name or a layout name... makes it difficult to rename it without breaking a solution.
Simply use FileMaker internal IDs instead.
To get the ID of a FileMaker item, pass its name to the function, then use the function the other way around in your calculations (pass the ID to it, and get the name)
Examples
Sample input
FM_Name_ID ( "MyLayout" ; "L" ; "" ; "" )
FM_Name_ID ( 112 ; "L" ; "" ; "" )
Sample output
112
"MyLayout"
Function code
/* FM_Name_ID ( _Name_ID ; _TLFSV ; _fileName ; _layoutName )
Fabrice Nordmann
http://www.1-more-thing.com
Avoids hard-coding in FileMaker by using IDs instead of names
v.1.6, Mar 2009
Accepts field parameters such as FM_Name_ID ( 1065234::24 ; "F" ; "" ; "" )
v.1.5.2, Feb 2009
Removes the repetition number if a fieldname with a repetition number is passed ( field[n]). Does not handle field names with [ anymore.
v.1.5.1, Dec 2008
Documentation update (thanks to Kevin Frank's comment)
v.1.5, Oct 2008
Documentation error fix
Returns an empty result if item not found
v.1.4, Aug 2008
Bug fix (major) : could return erroneous result if an item ID was found in another ID.
v.1.3, July 2008
A field ID can be obtained by passing its full name (with table occurrence) in _Name_ID and leaving _layoutName empty
e.g. FM_Name_ID ( "myTable::myField" ; "F" ; "" ; "" )
v.1.2, June 2008
Doesn't require Position value
v.1, May 2008
Requires: PositionValue ( _text ; _searchValue ; _start ; _occurrence )
if _Name_ID is an ID, returns the name
if _Name_ID is a name, returns the ID
_Name_ID is the name or the ID of a Table occurrence, a layout, or a field, a script or a value list
_TLFSV can be set to "Table", "Layout", "Field", "Script", or "ValueList". Or only the first character (T,L,F,S,V)
_fileName is optional (empty means current file)
_layoutName is valid only if _TLFSV contains "Field". Empty means current layout (or the field table occurrence, read the note below). The layout should be tied to the table occurrence of the field.
Note: for fields (_TLFSV = "F"), if you use the full field name (table::fieldname) AND an empty _layoutName parameter, the function will assume you are referring not to current layout but to the table occurrence found in the _TLFSV.
*/
Let ([
// _fileName is optional
_fileName = Case ( IsEmpty ( _fileName ) ; Get ( FileName ) ; _fileName )
; _layoutName = Case ( IsEmpty ( _layoutName ) ; Case ( PatternCount ( _Name_ID ; "::" ) ; GetValue ( Substitute ( _Name_ID ; "::" ; ¶ ) ; 1 ) ; Get ( LayoutName )) ; _layoutName )
; _layoutName = Case ( Int ( _layoutName ) = _layoutName and Length ( _layoutName ) = 7 ; FM_Name_ID ( _layoutName ; "T" ; _fileName ; "" ) ; _layoutName )
; _p = _Name_ID
// allow _TLFSV to be only the first character (T,L,F,S,V)
; _t = Left ( _TLFSV ; 1 )
; _t = Case ( _t = "T" ; "Table" ; _t = "L" ; "Layout" ; _t = "F" ; "Field" ; _t = "S" ; "Script" ; _t = "V" ; "ValueList" )
; _p = Case ( _t = "Field" and PatternCount ( _p ; "[" ) ; Left ( _p ; Position ( _p ; "[" ; 10000 ; -1 ) -1 ) ; _p ) // remove the repetition number
; _p = Case ( _t = "Field" and PatternCount ( _p ; "::" ) ; Replace ( _p ; 1 ; Position ( _p ; "::" ; 1 ; 1 ) + 1 ; "" ) ; _p ) // for fields, do not take TO
; _endOfString = "( \"" & _fileName & "\"" & Case ( _t = "field" ; "; \"" & _layoutName & "\"" ) & ")"
; _names = Evaluate ( _t & "Names" & _endOfString )
; _ids = Evaluate ( _t & "IDs" & _endOfString )
];
Case ( _p = GetAsNumber ( _p )
// ID -> Name
; Case ( not IsEmpty ( FilterValues ( _p ; _ids )) ; GetValue ( _names ; Let ([ _text = _ids ; _item = _p ; _adj = ¶ & _text & ¶ ] ; PatternCount ( Left ( _adj ; Position ( _adj ; ¶ & _item & ¶ ; 1 ; 1 ) + 1 ) ; ¶ ))))
// Name -> ID
; Case ( not IsEmpty ( FilterValues ( _p ; _names )) ; GetValue ( _ids ; Let ([ _text = _names ; _item = _p ; _adj = ¶ & _text & ¶ ] ; PatternCount ( Left ( _adj ; Position ( _adj ; ¶ & _item & ¶ ; 1 ; 1 ) + 1 ) ; ¶ ))))
)
)
// ===================================
/*
This function is published on FileMaker Custom Functions
to check for updates and provide feedback and bug reports
please visit http://www.fmfunctions.com/fid/82
Prototype: FM_Name_ID( _Name_ID; _TLFSV; _fileName; _layoutName )
Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
Last updated: 06 February 2010
Version: 1.9
*/
// ===================================
/* FM_Name_ID ( _Name_ID ; _TLFSV ; _fileName ; _layoutName )__LITBR____LITBR__Fabrice Nordmann__LITBR__http://www.1-more-thing.com__LITBR____LITBR__Avoids hard-coding in FileMaker by using IDs instead of names__LITBR____LITBR__v.1.6, Mar 2009__LITBR__ Accepts field parameters such as FM_Name_ID ( 1065234::24 ; "F" ; "" ; "" )__LITBR__v.1.5.2, Feb 2009__LITBR__ Removes the repetition number if a fieldname with a repetition number is passed ( field[n]). Does not handle field names with [ anymore.__LITBR__v.1.5.1, Dec 2008__LITBR__ Documentation update (thanks to Kevin Frank's comment)__LITBR__v.1.5, Oct 2008__LITBR__ Documentation error fix__LITBR__ Returns an empty result if item not found__LITBR__v.1.4, Aug 2008__LITBR__ Bug fix (major) : could return erroneous result if an item ID was found in another ID.__LITBR__v.1.3, July 2008__LITBR__ A field ID can be obtained by passing its full name (with table occurrence) in _Name_ID and leaving _layoutName empty__LITBR__ e.g. FM_Name_ID ( "myTable::myField" ; "F" ; "" ; "" )__LITBR__v.1.2, June 2008__LITBR__ Doesn't require Position value__LITBR__v.1, May 2008__LITBR__ Requires: PositionValue ( _text ; _searchValue ; _start ; _occurrence )__LITBR____LITBR__if _Name_ID is an ID, returns the name__LITBR__if _Name_ID is a name, returns the ID__LITBR____LITBR___Name_ID is the name or the ID of a Table occurrence, a layout, or a field, a script or a value list__LITBR___TLFSV can be set to "Table", "Layout", "Field", "Script", or "ValueList". Or only the first character (T,L,F,S,V)__LITBR___fileName is optional (empty means current file)__LITBR___layoutName is valid only if _TLFSV contains "Field". Empty means current layout (or the field table occurrence, read the note below). The layout should be tied to the table occurrence of the field.__LITBR____LITBR__Note: for fields (_TLFSV = "F"), if you use the full field name (table::fieldname) AND an empty _layoutName parameter, the function will assume you are referring not to current layout but to the table occurrence found in the _TLFSV.__LITBR____LITBR__*/__LITBR____LITBR__Let ([ __LITBR__// _fileName is optional__LITBR__ _fileName = Case ( IsEmpty ( _fileName ) ; Get ( FileName ) ; _fileName )__LITBR__; _layoutName = Case ( IsEmpty ( _layoutName ) ; Case ( PatternCount ( _Name_ID ; "::" ) ; GetValue ( Substitute ( _Name_ID ; "::" ; ¶ ) ; 1 ) ; Get ( LayoutName )) ; _layoutName )__LITBR__; _layoutName = Case ( Int ( _layoutName ) = _layoutName and Length ( _layoutName ) = 7 ; FM_Name_ID ( _layoutName ; "T" ; _fileName ; "" ) ; _layoutName )__LITBR__; _p = _Name_ID__LITBR____LITBR__// allow _TLFSV to be only the first character (T,L,F,S,V)__LITBR__; _t = Left ( _TLFSV ; 1 )__LITBR__; _t = Case ( _t = "T" ; "Table" ; _t = "L" ; "Layout" ; _t = "F" ; "Field" ; _t = "S" ; "Script" ; _t = "V" ; "ValueList" )__LITBR__; _p = Case ( _t = "Field" and PatternCount ( _p ; "[" ) ; Left ( _p ; Position ( _p ; "[" ; 10000 ; -1 ) -1 ) ; _p ) // remove the repetition number__LITBR__; _p = Case ( _t = "Field" and PatternCount ( _p ; "::" ) ; Replace ( _p ; 1 ; Position ( _p ; "::" ; 1 ; 1 ) + 1 ; "" ) ; _p ) // for fields, do not take TO__LITBR__; _endOfString = "( \"" & _fileName & "\"" & Case ( _t = "field" ; "; \"" & _layoutName & "\"" ) & ")"__LITBR__; _names = Evaluate ( _t & "Names" & _endOfString )__LITBR__; _ids = Evaluate ( _t & "IDs" & _endOfString )__LITBR__];__LITBR____LITBR__Case ( _p = GetAsNumber ( _p )__LITBR__// ID -> Name__LITBR__; Case ( not IsEmpty ( FilterValues ( _p ; _ids )) ; GetValue ( _names ; Let ([ _text = _ids ; _item = _p ; _adj = ¶ & _text & ¶ ] ; PatternCount ( Left ( _adj ; Position ( _adj ; ¶ & _item & ¶ ; 1 ; 1 ) + 1 ) ; ¶ ))))__LITBR__// Name -> ID__LITBR__; Case ( not IsEmpty ( FilterValues ( _p ; _names )) ; GetValue ( _ids ; Let ([ _text = _names ; _item = _p ; _adj = ¶ & _text & ¶ ] ; PatternCount ( Left ( _adj ; Position ( _adj ; ¶ & _item & ¶ ; 1 ; 1 ) + 1 ) ; ¶ ))))__LITBR____LITBR__)__LITBR__)__LITBR____LITBR__// ===================================__LITBR__/*__LITBR____LITBR__ This function is published on FileMaker Custom Functions__LITBR__ to check for updates and provide feedback and bug reports__LITBR__ please visit http://www.fmfunctions.com/fid/82__LITBR____LITBR__ Prototype: FM_Name_ID( _Name_ID; _TLFSV; _fileName; _layoutName )__LITBR__ Function Author: Fabrice (http://www.fmfunctions.com/mid/37)__LITBR__ Last updated: 06 February 2010__LITBR__ Version: 1.9__LITBR____LITBR__*/__LITBR__// ===================================
Login or register to comment
Create a new account with fmcustomfunctions.com or login to post a comment.
Comments
04 December 2008
One minor error -- the reference to "_Table_Layout_Field_Script_ValueList" needs to be changed to "_TLFSV"
Regards,
Kevin
04 December 2008
Thanks for the comment. Yes, I use it all the time, and it simply changed my life.
Indeed, I had changed the name of the parameter to make it shorter. It's fixed now.
Thanks !
Fabrice
19 December 2008
Note: for fields (_TLFSV = "F"), if you use the full field name (table::fieldname) AND an empty _layoutName parameter, the function will assume you are referring not to current layout but to the table occurrence found in the _TLFSV.
06 February 2009
http://my.advisor.com/doc/19569
27 February 2009
15 June 2009
07 September 2009
(Edited by Eric Sod on 07/09/09 )