- 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 event type calculation
- Use cases
- API
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:
These limitations apply to all of the specified methods.
Batch add app items
By using
Application.batch().save()
, you can, in a single request:When listing the items to be created, you can use the following in the method:
An array, to create a specific number of data items.
await Application.batch().save().items(orders).all(); // Here `orders` is an array of app items that were changed
A generator, to work with a large volume of data and dynamically create items one by one until the set number is reached. Then the created objects are saved in the database. This way the memory of the worker service is not overloaded.
await 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
For more information on
Application.batch().save()
see the following articles:Batch update of app item fields
You can use the method
Application.batch().update()
to update many fields in one request. You can:When writing a script with
Application.batch().update()
, you can define criteria for the items to be updated using theset()
method, where: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
Application.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
When using the
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:
var 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
For more information on using
Application.batch().update()
, also see the following articles:Batch delete app items
You can use the
Application.batch().delete()
item to delete multiple app items in a single request. You can:When using the
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:
var count = await Application.batch() .delete() // Define search criteria for the items to be deleted .where(f => f.number.gte(10)) .size(100) .all();,
For more information on using
Application.batch().delete()
, also see the following articles: