Beside the parameters explicitly passed to a query, there is also a pre-defined parameter ‘$context’ containing various data about the user and the client that is executing the query.
‘$context’ contains an XML fragment like this:
<lc:LoginContext
xmlns:lc="http://www.teradp.com/schemas/GN4/1/LoginContext.xsd"
UserId="obj1705"
UserName="teradp\mimo"
HomeFolderId="1431"
HomeFolderName="mimo"
HomeFolderPath="/system/users/mimo">
<Pars>
<add key="..." value=="..."/>
...
</Pars>
</lc:LoginContext>
<oc:OperationContext
xmlns:oc="http://www.teradp.com/schemas/GN4/1/OperationContext.xsd"
UtcNow="2012-08-22T15:43:02.002Z"
Now="2012-08-22T10:43:02.002"/>
Use this information to write queries based on the current user or on the execution date-time. For example
gn4:story[gn4:creatorRef/@idref=$context/lc:LoginContext/@UserId]
returns all stories created by the current user, whereas
gn4:task[@dueDate < $context/oc:OperationContext/@UtcNow]
returns all tasks that have a due-date in the past.
gn4:variantType[@name=$context/lc:LoginContext/lc:Pars/lc:add[@key='archiveVariantName']/@value]
returns the variant type specified by the archiveVariantName parameter of the current user.
Note how ‘$context’ in GNQuery has the same structure of the ‘$context’ parameter available in XSL transformation, but it contains less information.