Skip to main content

Filter Request

A Filter Request is used as a part of a Query Request to filter records retrieved when calling a find method. It is analogous to the WHERE clause in an SQL query. Only records that meet the condition specified in the Filter Request will be returned.

Code Examples

To get an empty filter request object, use the newFilterRequest method:

filterRequest = system.mes.query.newFilterRequest()

Here is an example of how to use a Filter Request to retrieve all materials created in 2024 that contain "can" in their name.

filterRequestOne = system.mes.query.newFilterRequest()  
filterRequestOne["field"] = "createdDate"
filterRequestOne["condition"] = "between"
filterRequestOne["minDateValue"] = "2024-01-01T00:00:00Z"
filterRequestOne["maxDateValue"] = "2025-01-01T00:00:00Z"

filterRequestTwo = system.mes.query.newFilterRequest()
filterRequestTwo["field"] = "name"
filterRequestTwo["condition"] = "contains"
filterRequestTwo["stringValue"] = "can"

filters = [filterRequestOne, filterRequestTwo]

queryRequest = system.mes.query.newQueryRequest()
queryRequest["filters"] = filters
result = system.mes.material.findMaterials(**queryRequest)

Parameters

TypeNameRequired
Stringfieldrequired
Stringtypenot required (automatically determined)
Stringconditionrequired
StringstringValueone or more values are required
SumbernumberValueone or more values are required
StringdateValueone or more values are required
NumberminNumberValueone or more values are required
NumbermaxNumberValueone or more values are required
StringminDateValueone or more values are required
StringmaxDateValueone or more values are required

Field

The field can be any field of the object being queried. It should be formatted in camelCase. Here is one way to see what fields are available for a given object:

material = system.mes.material.newMaterial()
print(material)

This will print an empty material object with all available fields.

Conditions

Conditions can be expressed in uppercase or lowercase and with or without underscore spacing. Here are the available conditions that can be used in a Filter Request:

ConditionReadable FormatCompatible TypesSQL Equivalent
EQUALSequalsstring, number, boolean, date=
NOT_EQUALSnot equalsstring, number, boolean, date!=, NOT =, <>
TRUEtrueboolean= TRUE
FALSEfalseboolean= FALSE
CONTAINScontainsstringLIKE '%value%'
STARTS_WITHstarts withstringLIKE 'value%'
ENDS_WITHends withstringLIKE '%value'
GREATER_THANgreater thannumber, date>
GREATER_THAN_OR_EQUAL_TOgreater than or equal tonumber, date>=
LESS_THANless thannumber, date<
LESS_THAN_OR_EQUAL_TOless than or equal tonumber, date<=
BETWEENbetweennumber, dateBETWEEN min AND max

Value

Use the value property that corresponds the type of the specified field. If the condition is BETWEEN, use either the minNumberValue and maxNumberValue properties or the minDateValue and maxDateValue properties.

Field TypePropertyProperty when using the BETWEEN condition
stringstringValue
numbernumberValueminNumberValue and maxNumberValue
datedateValueminDateValue and maxDateValue