Configure return results data
Summarize
Summary of Configure Return Results Data
The Mobile SDK allows you to interact with a ServiceNow instance through REST endpoints, enabling you to customize the data returned. Using the FetchConfiguration API, you can specify which records and fields to retrieve, as well as the number of records to return. It is recommended to maintain consistent FetchConfiguration across CRUD operations for a model type to avoid JSON Decoding failures.
Show less
Key Features
- Configurable Record Selection: Use the Filter object to define specific records based on criteria and sorting requirements. This is done via the sysparmquery parameter in the REST API.
- Flexible Filtering Options:
- Filter by criteria: Allows filtering with conditions that can be combined using OR logic.
- Filter by keywords: Enables filtering using keywords and conditions that can be combined with AND or OR logic.
- Field Configuration: The FieldReadConfiguration object allows you to set which fields are included in the return results, along with their format, such as display values or actual values.
Key Outcomes
By configuring return results effectively, you can streamline data retrieval processes, ensuring that only relevant information is fetched. This leads to enhanced performance and usability when interacting with ServiceNow data through the Mobile SDK.
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 object within a FetchConfiguration call enables you to define the filter and sort requirements for 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 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:
val activeIncidents = BooleanSimpleCondition.conditionIs("active", true) val assignedToEmpty = StringSimpleCondition.isEmpty("assigned_to") val assignedToAbel = StringSimpleCondition.conditionIs("assigned_to", "Abel Tuter") val assignedToAbelOrEmpty = CompoundCondition( ConditionUtils.CompoundOperator.OR, listOf(assignedToEmpty, assignedToAbel)) val needToReassign = Criteria().addConditions(listOf(activeIncidents, assignedToAbelOrEmpty)) val highEscelations = StringSimpleCondition.conditionIs("escalation", "2") val overdueEscelations = StringSimpleCondition.conditionIs("escalation", "3") val highOrOverdueEscelations = CompoundCondition(ConditionUtils.CompoundOperator.OR, listOf(highEscelations, overdueEscelations)) val needToHandleEscalation = Criteria().addCondition(highOrOverdueEscelations) val myPrioritiesForTodayFilter = Filter(listOf(needToReassign, needToHandleEscalation)) // Get record using filter val response = runCatching { getNowTableService()?.records( "sn_customerservice_case", FetchConfiguration(myPrioritiesForTodayFilter, 10) )?.execute() }To use this type of filtering, use the Filter(criteriaList: List<Criteria>, sortBy: List<Sort>? = null) function.
- Filter by keywords and conditions. This filter enables you to filter records based on
specific keywords and conditions that can be AND'd or OR'd together.
For example:
val keywords = "iOS 13 | iOS 14" val conditionA = BooleanSimpleCondition.conditionIs(testField, true) val conditionB = BooleanSimpleCondition.conditionIs(testField2, false) val sortA = Sort(testField, ConditionUtils.SortOperator.ORDER_ASC) val filter = Filter(conditions = listOf(conditionA, conditionB), keywords = keywords, sortBy = listOf(sortA)) assertEquals(filter.query().second, "${conditionA.makeConditionQuery()}^${conditionB.makeConditionQuery()}^123TEXTQUERY321=$keywords^EQ^${sortA.makeSortQuery()}")To use this type of filtering, use the Filter - Filter(conditions: List<Condition>, keywords: String? = null, sortBy: List<Sort>? = null) function.
Configuring the specific fields to return
- display values
- actual values
- exclude reference links