Query Request
In Tamaki MES, you can query the database using a structured method known as a query request. A query request allows you to specify pagination, sorting, and filtering parameters to refine the data you retrieve without needing to write an SQL query. This guide will walk you through the components of a query request and provide examples of how to use it effectively.
Query requests can be used with the following methods
- system.mes.material.findMaterials
- system.mes.material.findMaterialClasses
- system.mes.material.findMaterialReasonCodes
- system.mes.personnel.findPeople
- system.mes.personnel.findDepartments
- system.mes.role.findRoles
- system.mes.location.findLocations
- system.mes.inventory.findLots
- system.mes.operation.findOperations
- system.mes.operation.findOperationRecords
- system.mes.productionOrder.findProductionOrders
- system.mes.customer.findCustomers
- system.mes.schedule.findSchedules
- system.mes.unitOfMeasure.findUnitOfMeasureConversions
Pagination
Pagination is used to limit the number of records returned by a query. This is useful when working with large datasets.
The pageSize
parameter specifies the number of records to return, and the pageIndex
parameter specifies the page
number to return. If either parameter is not specified, pagination is disabled and all records that meet the filter
criteria will be returned.
Sorting
Sorting is used to order the records returned by a query. The sortFields
parameter specifies the fields to sort by.
Multiple fields can be specified in a list in the order to be sorted by, and should be formatted in camelCase. The
sortDirection
parameter specifies the direction to sort in. Accepted values are "Ascending" or "Descending" which
can also be abbreviated as "asc" or "desc".
Filtering
Only records that match the conditions specified by the filters will be returned. The filters
parameter can be a
list of one or more Filter Requests that define conditions to filter by. If left empty, all
records that meet the pagination and sorting criteria will be returned.
Alternatively, the filter property of a column of a perspective table can be used directly in place of a Filter Request.
To do this, combine the filters into a list and pass them to the filters
parameter of the Query Request.
Code Examples
To get an empty query request object, use newQueryRequest:
queryRequest = system.mes.query.newQueryRequest()
Here is an example of how to use a Query Request to retrieve the first ten materials created in 2024 sorted by their name.
queryRequest = system.mes.query.newQueryRequest()
queryRequest["pageSize"] = 10
queryRequest["pageIndex"] = 0
queryRequest["sortFields"] = ["name"]
queryRequest["sortDirection"] = "Ascending"
filterRequest = system.mes.query.newFilterRequest()
filterRequest["field"] = "createdDate"
filterRequest["condition"] = "between"
filterRequest["minDateValue"] = "2024-01-01T00:00:00Z"
filterRequest["maxDateValue"] = "2025-01-01T00:00:00Z"
filters = [filterRequest]
queryRequest["filters"] = filters
result = system.mes.material.findMaterials(**queryRequest)