Template parameters

Using template parameters

You can use parameters in your query text that will be replaced by sensenet in the background. This lets you create dynamic queries. For example it is possible to present the top 5 news of the day or listing the content modified by the currently logged in user.

The usage of parameters is easy: just put them into the query between double @@ signs:

ModifiedBy:@@CurrentUser@@

List of built-in template parameters

These are the built-in parameters that you can use in your queries:

Parameter nameDescription
CurrentUserRepresents the currently logged in user
CurrentDateCurrent date, meaning the very start of the day, e.g.:9/17/2010 00:00:00
CurrentTimeCurrent time, e.g.:10/23/2010 14:30:00
CurrentMonthCurrent month
CurrentContentCurrent content
TodayEquivalent to CurrentDate and CurrentDay: represents the start of the current day (00:00 AM).
YesterdayStart of the previous day.
TomorrowStart of the next day.
CurrentWeekStart of the current week. This builds on the first weekday defined by the current culture (which is Sunday in some cultures, Monday in others).
CurrentMonthStart of the current month.
CurrentYearStart of the current year.
NextWorkdayStart of the next workday. It skips weekends but it does not know anything about holidays.
NextWeekStart of the next week. This builds on the first weekday defined by the current culture.
NextMonthStart of the next month.
NextYearStart of the next year.
PreviousWorkdayStart of the previous workday. It skips weekends but it does not know anything about holidays.
PreviousWeekStart of the previous week. This builds on the first weekday defined by the current culture.
PreviousMonthStart of the previous month.
PreviousYearStart of the previous year.

Let's see some examples.

The following example results the car content modified with the current user:

Copy
GET https://example.com/OData.svc/Root?metadata=no&query=Type:Car AND ModifiedBy:@@CurrentUser@@
🛈 Special characters should be URL encoded

See another example query that returns the list of today's events:

Copy
GET https://example.com/OData.svc/Root?metadata=no&query=TypeIs:Task AND StartDate:>@@Today@@
🛈 Special characters should be URL encoded

Templates with properties

If the parameter represents another content (like CurrentUser), you can use any field of that content by naming it after the parameter and a dot (. sign):

The following query returns every task that is created by the current user and has its due date in the next week:

Copy
GET https://example.com/OData.svc/Root?metadata=no&query=+TypeIs:Task +DueDate:@@NextWeek@@ +AssignedTo:'@@CurrentUser@@'
🛈 Special characters should be URL encoded
 

Properties can also be chained like in the next example where we query for get the list of users who where created before the current user's manager was:

Copy
GET https://localhost:44362/OData.svc/Root?metadata=no&query=TypeIs:User +CreationDate:<@@CurrentUser.Manager.CreationDate@@
🛈 Special characters should be URL encoded

Template expressions

You can also use simple value modifiers (a '+' or '-') in template values (e.g. dates or numbers). This is extremely useful in case of dates, when you want your query to contain dates in the past or future. You may use any one of the date templates above, or any content property that is a date or number.

For example lets see how to get the list of items that were created in the last five days:

Copy
GET https://example.com/OData.svc/Root?metadata=no&query=TypeIs:Task AND StartDate:>@@CurrentDate-5days@@
🛈 Special characters should be URL encoded

It can also be used in a method-like syntax:

Copy
GET https://example.com/OData.svc/Root?metadata=no&query=TypeIs:Task AND StartDate:<@@CurrentDate.AddDays(-5)@@
🛈 Special characters should be URL encoded

The following list contains the units you may use in an expression (with a shortcut in parenthesis if exists):

seconds (s), minutes (m), hours (h), days (d), workdays, months, weeks, years (y)