- 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
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 methods for batch adding or updating of the app item fields:
Application.batch().save()
— batch add app items;Application.batch().update()
— batch update app item fields;Application.batch().delete()
— batch delete app items. Please note:Batch add app items
By usingApplication.batch().save()
, you can, in a single request:await Application.batch().save().items(orders).all(); // Here `orders` is an array of app items that were changed
For more information onawait Application.batch().save().items((function*(){ // Set up batch saving of items and, into the items method, get the items to be created by the generator function for (var i = 0; i < 500; i++) { // Loop 500 times to create 500 items var item = Application.create(); // Create an item each time yield item // Return the created item from the generator } })()).all(); // Save all items
Application.batch().save()
see the following articles:Batch update of app item fields
You can use the methodApplication.batch().update()
to update many fields in one request. You can:Application.batch().update()
, you can define criteria for the items to be updated using theset()
method, where:1.\tSet the name of the field to be updated. You can only select an existing app field. 2.\tSpecify what to do with this field:
Application.batch().update().set('numberField', (f, op) => 1); // OK. The constant matches the field type `numberField` – Number Application.batch().update().set('numberField', (f, op) => ''); // Error. A string constant does not match the field type Number
Application.batch().update().set('numberField1', (f, op) => f.numberField2); // OK. The field types `numberField1` and `numberField2`are both numbers Application.batch().update().set('numberField1', (f, op) => f.strField); // Error. The string field `strField` cannot be matched to the `numberField1` number field
Application.batch().update().set('numberField', (f, op) => op.inc(f.numberField, 1)); // Increase the value of the `numberField` field by 1
Application.batch().update().set('strLocation', (f, op) => op.concat(f.strCountry, ',', f.strCity)); // The`strLocation` field will be updated as '{strCountry}, {strCity}', meaning it will contain both values separated by a comma
Application.batch().update().set('users', (f, op) => op.remove(user)); // User deleted
When using theApplication.batch().update().set('users', (f, op) => op.push(user, user1)); // Add two users to the end of the array. The type of the`user` and `user1` fields must be the same as the single item of the `users` field
Application.batch().update()
method, be aware of the following:set()
methods are independent of each other and do not affect one another. Therefore, the order in which they are listed does not matter. Example:
For more information 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, and `another_number` = value of the `number` field before update
Application.batch().update()
, also see the following articles:Batch delete app items
You can use theApplication.batch().delete()
item to delete multiple app items in a single request. You can:Application.batch().delete()
method, note that if the number of items to be deleted is not specified in the script, 10 items will be deleted by default. The maximum value is 10,000 items. Example:
For more information on usingvar count = await Application.batch() .delete() // Define search criteria for the items to be deleted .where(f => f.number.gte(10)) .size(100) .all();,
Application.batch().delete()
, also see the following articles: