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 content shared with the current user:

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=SharedWith%3A@@CurrentUser@@

// the special characters should be url encoded
// the actual query here is ?query=SharedWith:@@CurrentUser@@

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

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=TypeIs%3ACalendarEvent AND StartDate%3A@@Today@@

// the special characters should be url encoded
// the actual query here is ?query=TypeIs:CalendarEvent AND StartDate:@@Today@@

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
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=+TypeIs%3ATask +AssignedTo%3A'@@CurrentUser@@' +DueDate%3A@@NextWeek@@

// the special characters should be url encoded
// the actual query here is ?query=+TypeIs:Task +DueDate:@@NextWeek@@ +AssignedTo:'@@CurrentUser@@'
 

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
https://dev.demo.sensenet.com/OData.svc/Root/IMS?query=TypeIs%3AUser +CreationDate%3A%3C@@CurrentUser.Manager.CreationDate@@

// the special characters should be url encoded
// the actual query here is ?query=TypeIs:User +CreationDate:<@@CurrentUser.Manager.CreationDate@@

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
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=CreationDate%3A>@@CurrentDate-5days)@@

// the special characters should be url encoded
// the actual query here is ?query=CreationDate:<@@CurrentDate-5days@@

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

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=CreationDate%3A<@@CurrentDate.AddDays(-5)@@

// the special characters should be url encoded
// the actual query here is ?query=CreationDate:<@@CurrentDate.AddDays(-5)@@

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)