Parameters

Parameters let page users choose the values a dataset filters on, such as a date range, an asset or a workspace. OI OData datasets use their own set of keywords, which write each value in the correct OData format.

This article applies to version 26R2 and later of IFS OI Explorer. 

The OData keywords

Keyword What it does
ODataParam(name,datasetType
[,odataType])
Declares a dataset parameter and writes its value as an OData literal
ODataSortBy(defaultFields) Adds a sort order that the page can change
ODataUserParam(name,datasetType
[,odataType])
Like ODataParam, but reads a user parameter and declares no dataset parameter
ODataUserParamSortBy(defaultFields) Like ODataSortBy, but reads the sort order from user parameters

Keyword names are not case-sensitive. Parameter names are case-sensitive and can't contain spaces.


ODataParam

ODataParam(name, datasetType[, odataType])

Argument Meaning
name The parameter name, shown in Core Management and linked to page variables
datasetType The dataset parameter type: String, Integer, Decimal, Double, Boolean, DateTime, ZonedDateTime or Duration
odataType Optional. How the value is written into the query. If you leave it out, it is chosen from datasetType, as the table below shows.

Choosing the OData type

Field type Use Written as
Text ODataParam(x,string) 'WELL-A12'
Date and time ODataParam(x,datetime) 2026-09-01T00:00:00Z
Date only ODataParam(x,datetime,Date) 2026-09-01
Whole number ODataParam(x,integer) 42
Yes/no ODataParam(x,boolean) true
Duration ODataParam(x,duration) duration'P0DT12H00M00S'

When you leave out odataType, String gives String, Boolean gives Boolean, Integer gives Int32, Decimal gives Decimal, Double gives Double, DateTime and ZonedDateTime give DateTimeOffset, and Duration gives Duration. Write the third argument when you need something else, such as Date for a date-only field or Int64 for a large whole number. Writing it in full, as in ODataParam(x,string,String), still works.

Don't put quotes around the keyword. ODataParam adds them for text values:

✔ Name eq ODataParam(well,string) ✘ Name eq 'ODataParam(well,string)'

You can use the same parameter more than once in a query. Each use gets the same value.

Examples

Page views between two dates, by page:

AnalyticsEventDetails?$apply=filter(Name eq 'Open Page' and PageName ne null and Timestamp ge ODataParam(startTime,datetime) and Timestamp le ODataParam(endTime,datetime))/groupby((WorkspaceDisplayName,PageName),aggregate($count as PageViews))&$orderby=PageViews desc&$top=50

Security groups and roles that match a search term:

UserGroupRoles?$compute=Role/Name as RoleName,UserGroup/DisplayName as GroupName&$filter=contains(Role/Name,ODataParam(membership,string)) or contains(UserGroup/DisplayName,ODataParam(membership,string))&$select=RoleName,GroupName

Cases on one asset:

SapiCases?$filter=EntityName eq ODataParam(asset,string)&$select=Id,State,StartTime,EndTime,Reason

Things to know

  • One value per parameter. ODataParam takes a single value. A parameter that receives several values fails with an error. To match a list, use several parameters with or, or filter on a shared prefix with startswith.
  • Text values are made safe for you. ODataParam doubles single quotes and URL-encodes the value, so O'Brien, Oil & Gas, C++ and 50% all work as typed. Pass the value as the user entered it. An already-encoded value such as Oil%20Gas is encoded again and matches that exact text.
  • Parameters inside Union branches work the same way as anywhere else in the query.

ODataSortBy

ODataSortBy(defaultFields)writes &$orderby=<fields> into the query. If the page supplies a value for the ODataSortBy parameter, that value is used. Otherwise the default fields you write inside the brackets are used. If both are empty, nothing is written.

Put it at the very end of the query, straight after the last character, with no space and no & in front. The keyword adds its own &:

Workbooks?$compute=Workspace/Name as WorkspaceName&$select=Name,WorkspaceName,LastModifiedODataSortBy(LastModified desc)

With no page value, this becomes ...&$select=Name,WorkspaceName,LastModified&$orderby=LastModified desc. The page can supply a different sort, such as Name asc, in the ODataSortBy parameter. Don't also write a $orderby option in the same query.


ODataUserParam and ODataUserParamSortBy

These work exactly like ODataParam and ODataSortBy, but read their values from the request's user parameters instead of its dataset parameters, and don't add a parameter to the dataset. Use them where a page or integration supplies values as user parameters, in the same way as USERPARAM in SQL datasets.


ODataSkip and ODataTop

These two keywords page a dataset, the way FIRSTROW() and LASTROW() do in SQL datasets. ODataSkip() becomes the number of rows before the current page, and ODataTop() becomes the page size. Put them in $skip and $top, and always add an $orderby so the pages follow on from each other:

Workbooks?$select=Name,LastModified&$orderby=Name&$skip=ODataSkip()&$top=ODataTop()

They take no arguments. Using them adds three parameters to the dataset: EnablePaging, PageNumber and PageSize. On a page, bind PageNumber to the Page Number variable of a Paging Control, and set PageSize to the same value as the control's Page Size.

Page Number Page Size Becomes
1 10 $skip=0&$top=10
3 25 $skip=50&$top=25

When paging is on, the dataset adds $count=true for you, so the Paging Control knows how many pages there are. It publishes the total number of rows in its TotalRowCount parameter. Bind that to the control's Total Record Count variable. If your query already has a $count option, it is left as you wrote it.

Keep the page size at 1,000 or below. The service refuses a $top over 1,000 with a Bad Request, and a dataset reads at most 1,000 rows anyway. Without a $filter, $skip plus $top can reach at most 100,000 rows into an object. On objects that aren't database-backed, a count is refused once the object has more than 5,000 rows, and the dataset fails with a Bad Request. For those, write $count=false in the query to page without a total. See Limits and performance.

With EnablePaging off, ODataSkip() is 0 and ODataTop() is 1000, so the query returns the first 1,000 rows.


Filtering in a Data Table

When a Data Table shows an OI OData dataset, the filter box under each column heading filters in the service, not just the rows on screen. The dataset is read again with your filters added to its query, so a filter looks at every row of the object, and a paged table's page count follows the filtered total. You don't need to change the query. Filters add to any $filter the query already has, so the query's own $filter still applies. With every box empty, the dataset is read exactly as you wrote it.

What you can type depends on the column:

Column You type Example Matches
Text Some text pump Rows whose value contains the text, whatever its case
Number A number, with an optional operator >= 10 Rows at or above 10
Date A date, with an optional operator > 1/1/2011 Rows after 1 January 2011

The operators are =, >, <, >= and <=. Without one, = is used. Dates are matched by day, so = 3/2/2022 matches every time on that day. Type dates in your own date format, the one the table shows. Text that isn't a number, or isn't a date, in a number or date column is ignored.

The table waits for a moment after you stop typing before it reads the dataset again. Filtering changes which rows there are, so a paged table goes back to its first page.

Tables on other kinds of dataset filter the rows they have loaded, as they always have.


Optional filters

In SQL datasets, optional filters are often written as PARAM(x) IS NULL OR column = PARAM(x). OData has no equivalent short-circuit, so a filter on a parameter always applies.

Instead, create one dataset per combination you need, or filter on text with contains, where an empty value matches everything:

SentinelEvents?$filter=StartTime ge ODataParam(startTime,datetime) and contains(MonitorName,ODataParam(monitor,string))&$select=Entity,MonitorName,TestName,StartTime,Value&$orderby=StartTime desc&$top=1000

With monitor left empty, contains(MonitorName,'') is true for every row.


Keywords that don't work with this adaptor

These keywords are for SQL datasets. They fail with "This operation is not supported by OData adaptors":

Keyword Use instead
PARAM, USERPARAM ODataParam, ODataUserParam
PARAMS, USERPARAMS, PARAMSTABLE Several ODataParam keywords joined with or
SORTBY, USERPARAMSORTBY ODataSortBy, ODataUserParamSortBy
FIRSTROW, LASTROW ODataSkip() and ODataTop() in $skip and $top
ENTITYNAME $compute=... as <alias>

Next: Aggregation and Calculated Columns

Related: Dataset Queries · Writing Queries

 

Comments are closed