forked from petrowsky/fmpfunctions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
object.id.fmfn
149 lines (137 loc) · 5.58 KB
/
object.id.fmfn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* =====================================================================
* object.id ( object; type; file; layout )
*
* @object = supply either the name or internal id of an object
* (see types variable for supported objects)
* @type = (enum) One of the following
* "Table", "Layout", "Field", "Script", or "ValueList" or (T,L,F,S,V) for shorthand
* @file = [optional] specify the name of the file (if using multiple files) - empty implies current file
* @layout = [optional] required only if @type contains "Field".
* Empty implies current layout (or the field table occurrence, read the note below).
* The layout should be tied to the table occurrence of the field
*
* RETURNS: (mixed) Internal FileMaker ID if name of object is supplied
* and inverse if ID of object is supplied
*
* DEPENDENCIES: None
* AUTHOR: Fabrice Nordman
* NOTES: for fields (_TLFSV = "F"), if you use the full field name
* (table::fieldname) AND an empty var.layout parameter, the
* function will assume you are referring not to current layout but
* to the table occurrence found in the _TLFSV
*
* =====================================================================
*/
Let ([
file = If (
IsEmpty ( file );
Get ( FileName ); // use current file name... otherwise
file
);
layout = Case (
IsEmpty ( layout );
Case (
PatternCount ( object; "::" );
GetValue ( Substitute ( object; "::"; ¶ ); 1 );
Get ( LayoutName ) // default
);
layout // default
);
layout = Case (
Int ( layout ) = layout and Length ( layout ) = 7;
object.id ( layout; "T"; file; "" );
layout
);
var.object = object;
// Allow type to be a single character (T,L,F,S,V)
var.type = Left ( type; 1 );
var.type = Choose( Position ( "TLFSV"; var.type; 1; 1 ) - 1; "Table"; "Layout"; "Field"; "Script"; "ValueList" );
var.object = Case ( // remove the repetition number
var.type = "Field" and PatternCount ( var.object; "[" );
Left ( var.object; Position ( var.object; "["; 10000; -1 ) -1 );
var.object
);
var.object = Case ( // for fields, do not take TO
var.type = "Field" and PatternCount ( var.object; "::" );
Replace ( var.object; 1; Position ( var.object; "::"; 1; 1 ) + 1; "" );
var.object
);
var.endOfString = "( \"" & file & "\"" & Case ( var.type = "field"; "; \"" & layout & "\"" ) & ")";
var.names = Evaluate ( var.type & "Names" & var.endOfString );
var.ids = Evaluate ( var.type & "IDs" & var.endOfString )
];
Case (
var.object = GetAsNumber ( var.object );
// Convert ID -> Name
Case (
not IsEmpty ( FilterValues ( var.object; var.ids ));
GetValue ( var.names; Let ([
_text = var.ids;
_item = var.object;
_adj = ¶ & _text & ¶
];
PatternCount ( Left ( _adj; Position ( _adj; ¶ & _item & ¶; 1; 1 ) + 1 ); ¶ )
)
)
);
// Convert Name -> ID
Case (
not IsEmpty ( FilterValues ( var.object; var.names ));
GetValue ( var.ids; Let ([
_text = var.names;
_item = var.object;
_adj = ¶ & _text & ¶
];
PatternCount ( Left ( _adj; Position ( _adj; ¶ & _item & ¶; 1; 1 ) + 1 ); ¶ )
)
)
)
)
)
/*
Original function by Fabrice Nordmann
Reformatted by Matt Petrowsky
Avoids hard-coding in FileMaker by using IDs instead of names
v.1.6, Mar 2009
Accepts field parameters such as FMvar.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 var.name_id and leaving var.layout empty
e.g. FMvar.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 )
// Test code for raw data
Let ( [
f = Get ( FileName );
l = Get ( LayoutName )
];
List (
"--- TABLES ---";
TableNames ( f );
TableIDs ( f );
"--- LAYOUTS ---";
LayoutNames ( f );
LayoutIDs ( f );
"--- FIELDS ---";
FieldNames ( f; l );
FieldIDs ( f; l );
"--- SCRIPTS ---";
ScriptNames ( f );
ScriptIDs ( f );
"--- VALUE LISTS ---";
ValueListNames ( f );
ValueListIDs ( f )
)
)
*/