Configure return results data
Summarize
Summary of Configure Return Results Data
The Mobile SDK allows you to configure data returned from ServiceNow REST endpoints using the FetchConfiguration structure. This setup lets you specify which records and fields to return, as well as the number of records retrieved. Consistency in using the same FetchConfiguration across CRUD operations for a model type is crucial to prevent JSON decoding failures.
Show less
Key Features
- Filtering Records: Utilize the Filter structure within FetchConfiguration to filter and sort records. Filters can be initialized in various ways:
- Encoded Query: Use an encoded query string for filtering, such as retrieving active records with specific descriptions.
- Filter by Criteria: Create filters using OR conditions for complex queries, e.g., identifying active incidents assigned to specific users or those needing reassignment.
- Keywords and Conditions: Filter records based on keywords and multiple conditions that are AND'd together.
- Conditions: Apply filters that meet all specified conditions (AND'd), such as active records with specific SLA due dates.
- Field Configuration: Use the FieldReadConfiguration to determine which fields to return in results, allowing options for display values, actual values, or exclusion of reference links. This can enhance network efficiency by reducing data transfer.
Key Outcomes
By effectively configuring return results data, ServiceNow customers can streamline data retrieval processes, ensure relevant information is delivered, and improve the performance of their applications. Proper filtering and field configuration enable targeted data access, enhancing overall user experience and operational efficiency.
Within the Mobile SDK, when interacting with data from a ServiceNow instance through a REST endpoint, you can configure what data is passed back in the return results.
- The specific records to return from a table.
- The specific fields to return from the records.
- The number of records to return.
Configuring the specific records to return
The Filter structure within a FetchConfiguration call enables you to filter and sort the records that are fetched from a ServiceNow instance and passed back in the return results from a REST endpoint. This filter is passed in the sysparm_query parameter of the REST API endpoint. For additional information, see Table API.
- Filter by encoded queryencoded query. This type of
filter enables you to pass an encoded query that is applied to the records within the
specified table.For example, the following call only returns those records that are active and whose short description field contains the word "broken":
Filter(query: "active=true^short_descriptionLIKEbroken"To use this type of filtering, initialize the Filter structure using the Filter - init(query: String, queryCategory: String? = nil) function.
- Filter by criteria. This filter enables you to filter based on one or more filter
criteria that are OR'd together.For example, a manager has an employee Abel Tuter who is on PTO. They want to know if there are active incidents that are not assigned to anyone or assigned to Abel Tuter so they can assign/reassign them. They also want to see in that same list, all of the incidents that have high or overdue escalation so that they can also address those. The following shows how to create the necessary filters to obtain this data:
let activeIncidents = Condition.boolean(field: "active", .is(true)) let assignedToEmpty = Condition.string(field: "assigned_to", .isEmpty) let assignedToAbel = Condition.string(field: "assigned_to", .is("Abel Tuter")) let assignedToAbelOrEmpty = CompoundCondition.or([assignedToEmpty, assignedToAbel]) let needToReassign = Criteria(conditions: [activeIncidents, assignedToAbelOrEmpty]) let highEscelations = Condition.string(field: "escalation", .is("2")) let overdueEscelations = Condition.string(field: "escalation", .is("3")) let highORoverdueEscelations = CompoundCondition.or([highEscelations, overdueEscelations]) let needToHandleEscalation = Criteria(condition: highOrOverdueEscelations) let myPrioritiesForTodayFilter = Filter(criteria: [needToReassign, needToHandleEscalation])To use this type of filtering, initialize the Filter structure using the Filter - init(criteria criteriaList: [Criteria], sortBy: [Sort]? = nil, queryCategory: String? = nil) function.
- Filter by keywords and conditions. This filter enables you to filter records based on
specific keywords and conditions that are AND'd together.
For example, the following filters for all records that contain the keyword "iOS13 or iOS 14" and meet the specified condition sorted by testField.
testKeywordsAndConditionsAndSort() { let keywords = "iOS 13 | iOS 14" let conditionA = Condition.boolean(field: testField, .is(true)) let conditionB = Condition.boolean(field: testField2, .is(false)) let sortA = Sort.asc(testField) let filter = Filter(keywords: keywords, conditions: [conditionA, conditionB], sortBy: [sortA]) XCTAssertEqual(filter.query, "123TEXTQUERY321=\(keywords)^\(conditionA.query)^\(conditionB.query)^EQ^\(sortA.query)") }To use this type of filtering, initialize the Filter structure using the Filter - init(keywords: String? = nil, conditions: [Condition], sortBy: [Sort]? = nil) function.
- Filter by conditions. This filter enables you to filter records that meet all
specified conditions (AND'd together).
For example, the following filters for all records in which the Active field is "true" and the date value of the SLA due field is on "today" or any date after today.
// Where the record is active let condition1 = Condition.boolean(field: "active", .is(true)) // AND the date value of the SLA due field is on "today" or any date after today. let condition2 = Condition.dateTime(field: "sla_due", .atOrAfter(0, .daysAgoStart)) let filter = Filter(conditions: [condition1, condition2])To use this type of filtering, initialize the Filter structure using the Filter - init(conditions: [QueryProviding], sorts: [Sort]? = nil) function.
Configuring the specific fields to return
- display values
- actual values
- exclude reference links