- Home [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
- Getting started
- Manage types
- Global context and isolation
- Manage apps
- Batch actions with app items
- Manage external services
- Scripts in widgets
- Web components
- Access permissions
- Getting started with processes
- Getting started with signatures
- Getting started with file previews
- Getting started with the organizational chart
- Getting started with users and groups
-
Getting started with the
Table data type - Dynamic calculation of event type
- Use cases
- How to set up custom view of app items
- How to set up dynamic display of fields and widgets with a complex condition
- How to register a document
- How to calculate the number of days between two dates
- How to create a substitution for a user
- How to use pagination and sorting when searching for app items
- API
- Object types
- Data types
- Global constants
- Work with apps
- Web requests
- Access permissions
- Document flow
- Live Chats
- “Code” widget
- Signatures
- Business calendars
- Integration with IP telephony
- Integration with email marketing services
In this article
How to use pagination and sorting when searching for app items
Sorting allows you to place the elements of the search results array in ascending or descending order based on the values of one of the app item’s properties. For example, you can place all items of the Employees app in ascending order of employees’ age (based on the Age variable of the Number type in the app).
The Search.sort method receives two arguments. The first one is the code of the app property that is used for sorting (note that the Search and sort by field option needs to be enabled in the property’s settings). The second argument of the Boolean type defines whether the results need to be displayed in ascending order. If the value doesn’t evaluate to
true
, the system will place the results in descending order.const employees = await Context.fields.employee.app.search().sort('age',true).size(10000).all();
Pagination
Pagination is used to split the list of all search results into separate parts. This may be needed, for instance, if these results have to be processed in a script that runs for a long period of time. To avoid a situation where the timeout expires before all items are processed, you can pass them to the script in chunks.
Pagination is also needed when more than 10,000 app items need to be processed, as this is the largest number of results that the
search()
method can return.Let’s say the process consists of two Script activities.
The Script calculating the number of items activity includes a script that calculates the total number of app items to be processed and sets the starting value of the counter:
In this script:
contracts
is the name of the app that we work with.counter
andContext.data.total
store the total number of app items that need to be processed.Context.data.work_element
is a variable of the Number type; it’s a counter for items that search will be applied to.Context.data.str
is a variable of the String type that displays the number of items found.The second activity, Loading and processing the next 50 items, includes a script that is used to process one “chunk” of items:
In this script,
string
is a property of thecontracts
app (the one that we need to change).After the second script, there is a gateway. By default, it returns the process to the previous step to work with the next 50 items. This keeps happening until the condition
work_element >= complete
is met, which means that the number of processed items is equal or larger than the total number of items found in the app during search.