FetchXML Slugs
When writing any fetchxml on the portal, whether it is for lists, filters on buttons, or table permissions, you can inject certain values from the current...
Feature Overview
When writing any fetchxml on the portal, whether it is for lists, filters on buttons, or table permissions, you can inject certain values from the current state into the query. This article describes what is possible.
Design Details
Fetchxml is used extensively on the portal. When you specify Fetchxml on a list, the table permissions for that table is added to your query to construct a single fetch that includes all security restrictions. Typically these need to be filtered by the current logged in user, however there are situations where additional contextual filtering is required. Once the fetch is cunstructed, it is then run through a parser to replace any "slugs" with contextual values before the fetch is executed. This is a complex process and requires all parts to be correctly entered to ensure a valid fetchxml query is produced at the end. If the query is not valid, it will return no data. To inspect the final query, you can enable debug tracing for KlevrPortal by updating the appsettings.json file on your site and changing the following setting to "Debug" as below:
{
"Serilog": {
"MinimumLevel": {
...
"Override": {
...
"KlevrPortal": "Debug"
}
}
},
....
}
Every time a fetchxml query is executed, you will see a tracelog in the umbraco logs. It will show the original query, and the secured query where all permission conditions are added and slugs replaced. You can use this to evaluate where there might be problems in your query.
Available slugs and their meanings
The following slugs are available:
- @currentrecord - This will be replaced with the ID of the current record being edited on a form. This is useful to filter subgrids on a form by their related parent record. This filter is also special, as it is analysed and used to pre-populate the field automatically when creating a new record from a subgrid. So if you filter a subgrid of contacts on an account page using parentcustomer eq @currentrecord, then when the new button is used to create a new contact, the new contact's parentcustomer field will automatically be set to the account's id.
- @[querystringparameter] e.g. @refid - Any value in a condition that starts with @ and matches the name of a querystring parameter of the current page will be replaced by the value of that querystring. A good example is refid, which is added to pages when you open from a lookup or subgrid. This can then be used in filters on subgrids on the sub-page.
- @self - This is replaced with the current logged in user's id. @self is also special in that you can use it to find any field on the current logged in contact record, by specifying the field schema name e.g. @self.ws_age or @self.parentcustomerid You can also iterate through any parental (lookup) values to find fields on related records, for instance @self.parentcustomerid.name will give you the name of the account that the current logged in contact belongs to. You can keep traversing lookups as much as you want, for instance @self.parentcustomerid.klevr_typeid.klevr_name. The logged in contect does not need to have permissions to these records defined in the table permissions, as table permissions are not evaluated when doing this traversal. You can also not navigate 1:n or n:n, only n:1 is supported.
🚫 Out of Scope
- Traversing through 1:n or n:n relationships using @self.
📎 References
Last updated on