- 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]
- 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 - 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
Batch actions with app items
When you need to process a large number of app items in a single request, you can write a script using batch methods for adding or updating app item fields:
Application.batch().save()
— for batch adding app items;Application.batch().update()
— for batch updating fields of app items. Note: A maximum of 10000 items can be processed in a single request. This limitation applies to all mentioned methods.Batch adding of items
Using
Application.batch().save()
, you can perform the following actions in a single request:Save new items to the database.
Update the fields of existing items. In this case, specify their identifiers to locate the required items, make changes to them, and save the edited items to the database. When specifying the items to be created, the method allows you to use:
An array: To create a defined number of items;
await Application.batch().save().items(orders).all(); // Here `orders` is an array of app items with modifications
A generator: To work with large volumes by dynamically creating items one at a time until the specified number is reached, then saving them to the database. This avoids overloading the worker service memory on the server..
await Application.batch().save().items((function*(){ // Define package saving of app items and in the items method recive the items created by the generator function for (var i = 0; i < 500; i++) { // Perform the loop 500 times to create 500 items var item = Application.create(); // Each time create an item yield item // Return the created item from the generator } })()).all(); // Save all items
To learn more about
Application.batch().save()
see the following articles:[[Applicationbatchsaver | App item saving object]];
[[Applicationbatchsavebuilder |App item batch saving configuration objects]];
Batch actions with app items in a script .
Batch updating of app items
The
Application.batch().update()
method allows you to update multiple fields in a single request. You can:Define rules for updating;
Specify criteria for finding the items to be updated;
Limit the number of items to be updated. When writing a script with
Application.batch().update()
вyou can define criteria for the items to update using theset()
method. In this method:1.\tSpecify the name of the field to update. Only existing app fields can be selected. 2.\tDefine what to do with this field:
Application.batch().update().set('numberField', (f, op) => 1); // OK. The constant matches the `numberField`type – Number Application.batch().update().set('numberField', (f, op) => ''); // Error. A string constant is incompatible with the Number type
Application.batch().update().set('numberField1', (f, op) => f.numberField2); // OK. The types of app fields `numberField1` and `numberField2` are numbers Application.batch().update().set('numberField1', (f, op) => f.strField); // Error. The string field`strField` cannot be matched to the number field `numberField1`
Application.batch().update().set('numberField', (f, op) => op.inc(f.numberField, 1)); // Increment the `numberField` value by 1
Application.batch().update().set('strLocation', (f, op) => op.concat(f.strCountry, ',', f.strCity)); // The `strLocation` field will update as '{strCountry}, {strCity}', i.e. it will store two values separated by comma: country, city
Application.batch().update().set('users', (f, op) => op.remove(user)); // Remove the user
Important notes for using theApplication.batch().update().set('users', (f, op) => op.push(user, user1)); // Add two users to the array end. The type of the `user`, `user1` fields must be of the same type as the single item of the `users` field
Application.batch().update()
method :set()
methods of a single request are independent of each other, so their order does not matter. Example:
For more details on usingvar rows1 = await Application.batch() .update() .set('number', _ => 100) .set('another_number', f => t.number) .all(); var rows2 = await Application.batch() .update() .set('another_number', f => t.number) .set('number', _ => 100) .all(); // In both cases, `number` = 100, а `another_number` = value of the `number` field
Application.batch().update()
refer to: