A helper function to use as a callback to retrieve objects from the plug-in (e.g. to set variables). The function purpose is purely internal and technical, so it does not appear in the list of functions.
PyPop( slotNumber )
slotNumber
Number of the slot to pop from the cache.
If there's no error, then the function returns whatever was put into the specifed slot of the internal cache and clears the slot.
If there's an error, then the function returns a question mark (?
); use
PyLastError to get more information about the error. The function itself may
return the following errors:
If slotNumber
is not a number: The PyPop index parameter must be a
number, not {type}
, class TypeError
.
If slotNumber
is negative: The PyPop index parameter must be
non-negative (got {number})
, class ValueError
.
If there's no such slot or if the slot is empty: Got an invalid PyPop
index {number}
, class ValueError
.
It may also propagate errors from lower levels, e.g. when an object in the cache cannot be converted to a FileMaker format.
The function helps to work around the following shortcomings in FileMaker plug-in API:
No dedicated method to set a variable.
No way to modify container fields from SQL.
To solve these issues the plug-in keeps an internal cache that may hold an arbitrary number of objects. Plug-in functions may add objects to the cache and then use PyPop to retrieve them from FileMaker. This probably doesn't look helpful; here's how it works:
The plug-in adds a number of objects to the cache and remembers their slot numbers, for example 7 and 15.
The plug-in then constructs a FileMaker calculation expression like that:
Let( [ $foo = PyPop(7); $bar = PyPop(15) ]; "" )
Here “7” and “15” are the remembered slot numbers.
When the plug-in evaluates this expression, FileMaker calls PyPop as specified and as a result sets these variables to the objects from the cache.
This allows the plug-in not only return a single result, but also set an arbitrary number of variables.
This is the standard method in the plug-in and to use it you don't even need to know about PyPop: all you need is to return the results from your function like that:
def test(): return "OK", "$foo", 123, "$bar", [456, 789]
This will return OK
as the function result, set $foo
to 123
and
set 1st and 2dn repetitions of $bar
to 456
and 789
respectively.
PyPop may also be used in other cases; e.g. if you want to use SQL with FileMaker, you'll find that the API is not sufficient to modify container fields. PyPop may help in this case as well, but the required setup is more cumbersome than just using a script to pass the result in variables and then looping over them.