It seems that the index parameter for the GET_ATTR_VALUE cannot be dynamic but only a fixed number. That makes the function a lot less useful.
For example:
FIND ALL MyObject ORDER BY MyObject.LastAccessTime DESC
Session.OldestObjectID = GET_ATTR_VALUE ('MyObject', 'ID', SEARCH_COUNT - 1)
This results in an exception: “Third parameter of the GET_ATTR_VALUE function must indicate the index of the object instance in Context”
The same applies if try to use a variable:
FIND ALL MyObject ORDER BY MyObject.LastAccessTime DESC
Session.Index = SEARCH_COUNT - 1
Session.OldestObjectID = GET_ATTR_VALUE ('MyObject', 'ID', Session.Index )
This results in the same error.
In this specific case I can work around it, but I wonder why GET_ATTR_VALUE does not take variables or expressions for the index like most other functions.