Files
help365/platform/batch-actions.html
koziavin 00717a92fb
All checks were successful
Deploy Static Site / deploy (push) Successful in 6m6s
update
2025-05-29 16:42:45 +04:00

335 lines
36 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Batch actions with app items in scripts</title>
<meta name="generator" content="Help+Manual" />
<meta name="keywords" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="In BRIX, you can add and delete items, as well as update their fields in batches using batch methods in scripts written in the TypeScript language. This allows you to reduce..." />
<meta name="picture" content="" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Full documentation for BRIX365 platform. Low-code developer guide. User guide. Admin guide. Developer guide." />
<meta property="og:url" content="https://brix365.com/en/help" />
<meta property="og:image" content="" />
<link rel="icon" href="favicon.png" type="image/png" />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="./jquery-ui.min.css" />
<link rel="stylesheet" href="default.css" />
<link rel="stylesheet" href="./search-yandex.css" />
<link rel="stylesheet" href="./article.css" />
<link rel="stylesheet" href="./glossary.css" />
<link rel="stylesheet" href="./theme.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="helpman_settings.js"></script>
<script type="text/javascript" src="helpman_topicinit.js"></script>
<script type="text/javascript" src="highlight.js"></script>
<script type="text/javascript">
$(document).ready(function(){highlight();});
</script>
</head>
<body>
<script>!function(e,t,c,n,r,a,m){e.ym=e.ym||function(){(e.ym.a=e.ym.a||[]).push(arguments)},e.ym.l=1*new Date;for(var s=0;s<document.scripts.length;s++)if(document.scripts[s].src===n)return;a=t.createElement(c),m=t.getElementsByTagName(c)[0],a.async=1,a.src=n,m.parentNode.insertBefore(a,m)}(window,document,"script","https://mc.yandex.ru/metrika/tag.js"),ym(83179930,"init",{clickmap:!0,trackLinks:!0,accurateTrackBounce:!0,webvisor:!0})</script><noscript><div><img alt=""src=https://mc.yandex.ru/watch/83179930 style=position:absolute;left:-9999px></div></noscript>
<header class="header elma-365">
<div class="container">
<a class="header__logo" href="https://brix365.com/en/help">
<img src="./logo-en.svg" alt="header logo">
</a>
<!-- <div class="hero__search-form" id="search-panel">
<form class="search-form" onsubmit="ym(83180416,'reachGoal','poisk')">
<label class="search-form__label">
<span id="reset-search" class="search__icon"></span>
<input class="search-form__input" type="text">
</label>
<input class="search-form__submit" type="submit" value="Submit">
</form>
</div> -->
<div class="hero__search-form" id="search-panel"> <form class="search-form"> <label class="search-form__label"> <span id="reset-search" class="search__icon"></span> <input class="search-form__input" type="text"> </label> <input class="search-form__submit" type="submit" value="Submit"> </form> </div>
<div class="hero__search">
<a href="#" id="search-icon" class="hero__search-icon">
<img src="search-icon-white.svg" alt="search string">
</a>
<a href="#" id="side-menu-icon" class="hero__side-icon">
<img src="side_menu.svg" alt="side menu">
</a>
</div>
<div class="header__navi">
<ul class="header__list"><li><span class="solution-select"><span class="solution-select__selected"></span><svg width="7" height="4" viewBox="0 0 7 4" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L3.5 3.5L6 1" stroke="white" stroke-linecap="round" stroke-linejoin="round"/></svg><ul class="solution-select__list"><li><a class="project-link" href="https://brix365.com/en/help/platform/get-trial.html">Platform</a></li><li><a class="project-link" href="https://brix365.com/en/help/ecm/ecm-functions.html">ECM</a></li><li><a class="project-link" href="https://brix365.com/en/help/crm/crm_overview.html">CRM</a></li><li><a class="project-link" href="https://brix365.com/en/help/service/service-functions.html">Service</a></li><li><a class="project-link" href="https://brix365.com/en/help/projects/projects-functions.html">Projects</a></li><li><a class="project-link" href="https://brix365.com/en/help/business_solutions/-elma365-store.html">Business Solutions</a></li></ul></span></li><li><a href="https://api.brix365.com/en/" target="_blank">API</a></li><li><a href="https://tssdk.brix365.com/" target="_blank">SDK</a></li></ul>
</div>
</div>
</header>
<main class="main container">
<aside class="sidebar" id="sidebar">
<div class="sidebar__header">
<a class="header__logo" href="https://brix365.com/en/help">
<img src="./logo-light-en.svg">
</a>
<span class="sidebar__close elma-365-close" id="close"></span>
</div>
<div class="sidebar__wrapper" id="side-menu">
</div>
</aside>
<article class="article" id="article">
<div class="article-inner">
<div class="content">
<header class="article__header">
<div class="article__bread" style="display:flex; gap:10px;">
<span id="subcategory" class="search-res__item-category search-res__item-category_subcategory subcategory article__badge"></span>
<div class="topic__breadcrumbs">
<p>Low-code designer &gt; <a href="360006963072.html">App</a> &gt; <a href="app-data-in-scripts.html">Manage apps in scripts</a> / Batch actions with app items in scripts</p>
</div>
</div>
<div class="topic__title"><h1 class="p_Heading1"><span class="f_Heading1">Batch actions with app items in scripts</span></h1>
</div>
</header>
<section class="article__content">
<div class="scroll-top-inner">
<a href="#h1-article" class="scroll-top"></a>
</div>
<!-- Placeholder for topic body. -->
<p class="p_Normal">In BRIX, you can add and delete items, as well as update their fields in batches using batch methods in <a href="type-script.html" class="topiclink">scripts</a> written in the <a href="https://www.typescriptlang.org/" target="_blank" class="weblink">TypeScript</a> language. This allows you to reduce the load on the system and the impact of set limits when you need to process a large amount of data. For example, if you have an integration set up with a third-party system, you can import a product catalog into the app from that system.</p>
<p class="p_Normal">You can set the following methods in scripts:</p>
<ul style="list-style-type:disc">
<li class="p_Normal"><code><b>app.batch().save()</b></code> to add app items in batches.</li><li class="p_Normal"><code><b>app.batch().update()</b></code> to update fields of app items in batches.</li><li class="p_Normal"><code><b>app.batch().delete()</b></code> to delete app items in batches.</li></ul>
<p class="p_Normal">When writing scripts with methods for batch actions, please note the following conditions: </p>
<ul style="list-style-type:disc">
<li class="p_Normal">No more than 10 000 items are processed per request. This limitation applies to all the specified methods.</li><li class="p_Normal">To perform a batch action with items using a method, the user must have <a href="360007527512.html#assign" class="topiclink">permissions to import data from this app</a>.</li></ul>
<p class="p_Normal">In this article, we will look at examples of how to use methods in scripts. You can find more details in <a href="https://tssdk.brix365.com/en/latest/pages/quick-start/intro_batch.html" target="_blank" class="weblink">BRIX TS SDK</a>.</p>
<h2 class="p_Heading2"><span class="f_Heading2">Method for adding app items in batches</span></h2>
<p class="p_Normal">With <code><b>app.batch().save()</b></code>, you can process a batch of app items in a single request. </p>
<p class="p_Normal">Use this method to:</p>
<ul style="list-style-type:disc">
<li class="p_Normal">Save new items to the app.</li><li class="p_Normal">Update the fields of existing items. In this case, specify their identifiers so that you can use them to find the required items, make changes to them, and save the edited items in the database.</li></ul>
<h3 class="p_Heading3"><a id="use-case-1" class="hmanchor"></a><span class="f_Heading3">Use case for adding items in batches</span></h3>
<p class="p_Normal">Lets assume that a company uses the BRIX system, and marketing employees also work with a third-party service that stores product publications and customer comments.</p>
<p class="p_Normal">You can import information from this external service to BRIX in bulk allowing employees from related departments to view all data in one place. For this:</p>
<ol style="list-style-type:decimal">
<li value="1" class="p_Normal">Create apps for uploading publications and comments.</li><li value="2" class="p_Normal">Set up integration via <a href="extentions.html" class="topiclink">a custom module</a> and add two script buttons to the module interface:</li></ol>
<ul style="list-style-type:disc">
<li class="p_Normal"><span style="font-weight: bold;">Add Posts </span>to import all publications from a third-party service to BRIX.</li><li class="p_Normal"><span style="font-weight: bold;">Add Comments</span> to upload all comments to these publications.</li></ul>
<h3 class="p_Heading3"><span class="f_Heading3">Step 1: Create two apps</span></h3>
<p class="p_Normal">First, create <a href="360007235031.html" class="topiclink">apps</a> to import data into them. As you do so, add properties to the apps to match the fields of the publications and comments in the third-party system. Here is an example: &nbsp;</p>
<ul style="list-style-type:disc">
<li class="p_Normal"><span style="font-weight: bold;">Posts</span>. Contains the following properties:</li></ul>
<ul style="list-style-type:disc"><ul style="list-style-type:disc">
<li style="line-height: 1.20;"><span style="font-weight: bold;">Name</span> (<code><b>__name</b></code>). A system property, created automatically in BRIX.</li><li style="line-height: 1.20;"><span style="font-weight: bold;">Number</span> (<code><b>postID</b></code>). <a href="360009707032.html#number" class="topiclink">The Number (integer) type</a> for the identification number, by which the external system determines the link between the publication and its comments, i.e. the values of this field are equal in related items.</li><li style="line-height: 1.20;"><span style="font-weight: bold;">Creation date</span> (<code><b>__createdAt</b></code>). <a href="360009707032.html#date-time" class="topiclink">The Date/Time type</a> to store the date of post creation.</li><li style="line-height: 1.20;"><span style="font-weight: bold;">Title</span> (<code><b>title</b></code>). <a href="360009707032.html#string" class="topiclink">The String (string) type</a> for the title of the publication.</li><li style="line-height: 1.20;"><span style="font-weight: bold;">Text</span> (<code><b>body</b></code>). The <span style="font-weight: bold;">String (text)</span> type for the text of the publication.</li><li style="line-height: 1.20;"><span style="font-weight: bold;">Comments </span><code><b>comments</b></code>. <a href="360009707032.html#app" class="topiclink">The App (one) type</a> for a link to a related comment.</li></ul></li></ul>
<ul style="list-style-type:disc">
<li class="p_Normal"><span style="font-weight: bold;">Comments</span>. Contains the following properties:</li></ul>
<ul style="list-style-type:disc"><ul style="list-style-type:disc">
<li style="line-height: 1.20;"><span style="font-weight: bold;">Name</span> (<code><b>__name</b></code>). A system property created automatically in BRIX.</li><li style="line-height: 1.20;"><span style="font-weight: bold;">Number</span> (<code><b>postID</b></code>). The <span style="font-weight: bold;">Number (integer)</span> type for the identification number by which the external system determines the link between the publication and its comments, i.e. the values of this field are equal in the related items.</li><li style="line-height: 1.20;"><span style="font-weight: bold;">Creation date</span> (<code><b>__createdAt</b></code>). The <span style="font-weight: bold;">Date/Time</span> type to store the date of comment creation.</li><li style="line-height: 1.20;"><span style="font-weight: bold;">User's e-mail</span> (<code><b>email</b></code>). The <span style="font-weight: bold;">Email address</span> type for the email of the user who left the comment.</li><li style="line-height: 1.20;"><span style="font-weight: bold;">Message</span> (<code><b>body</b></code>). The <span style="font-weight: bold;">String (text)</span> type for the text of the comment.</li><li style="line-height: 1.20;"><span style="font-weight: bold;">Posts </span><code><b>post</b></code><span style="font-weight: bold;">.</span> The <span style="font-weight: bold;">App (one)</span> type for the link to the linked post.</li></ul></li></ul>
<p class="p_Normal">These properties will be used in the script to define the fields where the values sent from the external service will be written. Read more about filling in the <span style="font-weight: bold;">Comments</span> and <span style="font-weight: bold;">Posts</span> fields of the <span style="font-weight: bold;">App (one)</span> type in <a href="batch-actions.html#use-case-2" class="topiclink">Use case for updating item fields in batches</a>.</p>
<h3 class="p_Heading3"><span class="f_Heading3">Step 2: Configure data loading via a script</span></h3>
<p class="p_Normal">After creating the app, configure data import from the external system.</p>
<p class="p_Normal">Here is how:</p>
<ol style="list-style-type:upper-roman">
<li value="1" class="p_Normal">In the configured integration module, go to the <a href="extention-settings.html" class="topiclink">Settings</a> tab and click <span style="font-weight: bold;">Edit Form</span>.</li><li value="2" class="p_Normal">In the interface designer that opens:</li></ol>
<ul style="list-style-type:disc">
<li class="p_Normal">Create the <span style="font-weight: bold;">Add Posts</span> and <span style="font-weight: bold;">Add Comments</span> buttons.</li><li class="p_Normal">On the <span style="font-weight: bold;">Scripts</span> tab, write Client-side code using <code><b>app.batch().save()</b></code>. This code will import data into the app when the user clicks the <span style="font-weight: bold;">Add Posts</span> or <span style="font-weight: bold;">Add Comments</span> buttons.</li></ul>
<p class="p_Normal"><a class="dropdown-toggle" style="font-style: normal; font-weight: normal; color: #000000; background-color: transparent; text-decoration: none;" href="javascript:HMToggle('toggle','TOGGLE0186A1')">Code example</a></p>
<div id="TOGGLE0186A1" class="dropdown-toggle-body" style="text-align: left; text-indent: 0; line-height: 1.80; padding: 0 0 0 0; margin: 0 0 0 0;"><table style="border:none; border-spacing:0;">
<tr>
<td style="vertical-align:top; padding:0; border:none"><p class="p_CodeExample" style="white-space: normal; page-break-inside: avoid;"><span class="f_CodeExample">/* Client scripts module */</span><br />
<span class="f_CodeExample">declare const console: any;</span><br />
<span class="f_CodeExample">/*</span><br />
<span class="f_CodeExample">//Asynchronous function to import comments from the external service</span><br />
<span class="f_CodeExample">async function import_comments(): Promise&lt;void&gt; {</span><br />
<span class="f_CodeExample">//Request the external service to get comments</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;const result = await fetch('https://externalservicewebsite.com/comments');</span><br />
<span class="f_CodeExample">//Convert the response to JSON format</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;const comments = await result.json();</span><br />
<span class="f_CodeExample">//Initialize an array for storing comment items</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;const items: any = [];</span><br />
<span class="f_CodeExample">//Check each comment in the received list</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;for (let c of comments) {</span><br />
<span class="f_CodeExample">//Create a new comment item in the app</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;const item = Context.fields.commentapp.app.create();</span><br />
<span class="f_CodeExample">//Fill in the fields of the comment item</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;item.data.__name = c.name;</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;item.data.email = [{ { type: EmailType.Home, email: c.email }];</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;item.data.body = c.body;</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;item.data.postID = c.postId; </span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;items.push(item);</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;}</span><br />
<span class="f_CodeExample">//Save all created comment items in a batch</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;await Context.fields.commentapp.app.batch().save().items(items).all();</span><br />
<span class="f_CodeExample">}</span><br />
<span class="f_CodeExample">//Asynchronous function to import posts from the external service</span><br />
<span class="f_CodeExample">async function import_posts(): Promise&lt;void&gt; {</span><br />
<span class="f_CodeExample">//Request the external service to get posts</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;const result = await fetch('https:// externalservicewebsite.com/posts');</span><br />
<span class="f_CodeExample">//Convert the response into JSON format</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;const posts = await result.json();</span><br />
<span class="f_CodeExample">//Initialize an array for storing post items</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;const items: any = [];</span><br />
<span class="f_CodeExample">//Check each post in the received list</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;for (let p of posts) {</span><br />
<span class="f_CodeExample">//Create a new post item in the app</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;const item = Context.fields.postsapp.app.create();</span><br />
<span class="f_CodeExample">//Fill in the fields of the post item</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;item.data.__name = p.title;</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;item.data.body = p.body; </span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;item.data.postID = p.id;</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;items.push(item);</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;}</span><br />
<span class="f_CodeExample">//Batch save all created post items</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;await Context.fields.postsapp.app.batch().save().items(items).all();</span><br />
<span class="f_CodeExample">}</span></p>
</td>
</tr>
</table>
</div>
<ol style="list-style-type:upper-roman" start="3">
<li value="3" class="p_Normal">Save and publish the changes.</li></ol>
<p class="p_Normal">The buttons will then appear in the <a href="extention-settings.html#settings" class="topiclink">settings</a> of the integration module. The user can now click them to add new items to the <span style="font-weight: bold;">Posts</span> and <span style="font-weight: bold;">Comments</span> apps.</p>
<h2 class="p_Heading2"><span class="f_Heading2">Method for updating item fields in batches</span></h2>
<p class="p_Normal">To update multiple item fields in a single request, use the <code><b>app.batch().update()</b></code> method in the script. This allows you to:</p>
<ul style="list-style-type:disc">
<li class="p_Normal">Specify the rules for such an update.</li><li class="p_Normal">Define search criteria for items to be updated.</li><li class="p_Normal">Limit the number of items to be updated.</li></ul>
<h3 class="p_Heading3"><a id="use-case-2" class="hmanchor"></a><span class="f_Heading3">Use case for updating fields in batches</span></h3>
<p class="p_Normal">In <a href="batch-actions.html#use-case-1" class="topiclink">Use case for adding items in batches</a>, we transferred data from the external system to the <span style="font-weight: bold;">Posts</span> and <span style="font-weight: bold;">Comments</span> apps using the <code><b>app.batch().save()</b></code> method in the script. However, the <span style="font-weight: bold;">Posts</span> field in comment pages and <span style="font-weight: bold;">Comments</span> field in post pages are still empty. The links for these fields are not transferred from the external system, but are created in BRIX. </p>
<p class="p_Normal">Let's fill these empty fields with links to related items so that employees can quickly find the necessary information when working in these apps. </p>
<p class="p_Normal">To do this, we will use the <code><b>app.batch().update()</b></code> method to update the fields in bulk. &nbsp;</p>
<p class="p_Normal">In the third-party system, the link between publications and comments is defined through the <span style="font-weight: bold;">Number</span> (<code><b>postID</b></code>) field. The value in this field is the same in all the linked items. We will use this property in the script to find the required publications and add links in the <span style="font-weight: bold;">Posts</span> field to comment pages.</p>
<p class="p_Normal">To do this:</p>
<ol style="list-style-type:upper-roman">
<li value="1" class="p_Normal">In the customized integration module, go to the <a href="extention-settings.html" class="topiclink">Settings</a> tab and click <span style="font-weight: bold;">Edit Form</span>.</li><li value="2" class="p_Normal">In the interface designer that opens, add the <a href="button_widget.html" class="topiclink">Button</a> widget and name it <span style="font-weight: bold;">Update Links</span>.</li><li value="3" class="p_Normal">On the <span style="font-weight: bold;">Scripts</span> tab, write the code that will update the links between the items of the <span style="font-weight: bold;">Posts</span> and <span style="font-weight: bold;">Comments</span> apps. When the user clicks the <span style="font-weight: bold;">Update Links</span> button, the links in the <span style="font-weight: bold;">Post</span> fields will be updated in the comment pages.</li></ol>
<p class="p_Normal"><a class="dropdown-toggle" style="font-style: normal; font-weight: normal; color: #000000; background-color: transparent; text-decoration: none;" href="javascript:HMToggle('toggle','TOGGLE0186A2')">Sample code:</a></p>
<div id="TOGGLE0186A2" class="dropdown-toggle-body" style="text-align: left; text-indent: 0; line-height: 1.80; padding: 0 0 0 0; margin: 0 0 0 0;"><table style="border:none; border-spacing:0;">
<tr>
<td style="vertical-align:top; padding:0; border:none"><p class="p_CodeExample" style="white-space: normal; page-break-inside: avoid;"><span class="f_CodeExample">//Asynchronous function to update the Posts field in comments</span><br />
<span class="f_CodeExample">Async function update_comments(): Promise&lt;void&gt; {</span><br />
<span class="f_CodeExample">//Search for and retrieve posts from the Posts application</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;const posts = await Context.fields.postsapp.app.search().size(100).from(0).all();</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;for (let p of posts) {</span><br />
<span class="f_CodeExample">//Batch update the values in the Posts field in the comment pages by comparing the values in the Number (postID) field. If the values match, a link to the linked item is added to the Posts field.</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;await Context.fields.commentapp.app.batch().update().update().set(“post”, (f, op) =&gt; p).where((f) =&gt; f.postID.eq(p.data.postID ?? 0)).all();</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;}</span><br />
<span class="f_CodeExample">}</span></p>
</td>
</tr>
</table>
</div>
<ol style="list-style-type:upper-roman" start="4">
<li value="4" class="p_Normal">Save and publish the changes.</li></ol>
<p class="p_Normal">After that, the <span style="font-weight: bold;">Update Links</span> button will appear in the <a href="extention-settings.html#settings" class="topiclink">settings</a> of the integration module. Now, users can click it to update the <span style="font-weight: bold;">Posts</span> field in the comment pages.</p>
<h2 class="p_Heading2"><span class="f_Heading2">Method for deleting items in batches</span></h2>
<p class="p_Normal">You can use the <code><b>app.batch().delete()</b></code> method in the script to delete many app items in a single request. In doing so, you can:</p>
<ul style="list-style-type:disc">
<li class="p_Normal">Define search criteria for the items to be deleted.</li><li class="p_Normal">Specify the number of items to be deleted.</li></ul>
<h3 class="p_Heading3"><span class="f_Heading3">Use case for deleting items in batches</span> </h3>
<p class="p_Normal">In the previous use cases, we used a script <a href="batch-actions.html#use-case-1" class="topiclink">to add data from a third-party system</a> to the <span style="font-weight: bold;">Posts</span> and <span style="font-weight: bold;">Comments</span> apps and <a href="batch-actions.html#use-case-2" class="topiclink">update the fields of their items</a>.</p>
<p class="p_Normal">Now let's configure batch deletion of data using a script. We will add two buttons to the page of the third-party system integration module. When clicking them, the user will be able to delete outdated items of the <span style="font-weight: bold;">Posts</span> or <span style="font-weight: bold;">Comments</span> apps, for example, records that were created before 01.01.2024.</p>
<p class="p_Normal">To do this:</p>
<ol style="list-style-type:upper-roman">
<li value="1" class="p_Normal">In the integration module of the third-party system, go to the <span style="font-weight: bold;">Settings</span> tab and click the <span style="font-weight: bold;">Edit Form</span> button.</li><li value="2" class="p_Normal">In the interface designer that opens, add the <span style="font-weight: bold;">Button</span> widget, set the <span style="font-weight: bold;">Delete Posts</span> name and the <span style="font-weight: bold;">Script</span> type.</li><li value="3" class="p_Normal">Bind a batch deletion script to this button. Specify in it the criterion of searching for items and the number of records to be deleted in one request. When the script is executed, the number of such requests is determined automatically. In the use case, we will delete items created before 01.01.2024 in batches of 100 pieces.<br />
To do this, specify the <code><b>delete_posts</b></code> function name in the button settings on the <span style="font-weight: bold;">Main</span> tab in the <span style="font-weight: bold;">Executed script</span> field. Then click <span style="font-weight: bold;">Save</span> and <span style="font-weight: bold;">Open</span>.</li><li value="4" class="p_Normal">On the <span style="font-weight: bold;">Scripts</span> tab that opens, add the following script:</li></ol>
<p class="p_CodeExample" style="white-space: normal; page-break-inside: avoid;"><span class="f_CodeExample">// Asynchronous function to delete all items from the Posts app</span><br />
<span class="f_CodeExample">async function delete_posts(): Promise&lt;void&gt; {</span><br />
<span class="f_CodeExample">// specify a variable to track the number of items deleted </span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;let rows = 0;</span><br />
<span class="f_CodeExample">// use a loop to delete all items</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;do {</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp; &nbsp; &nbsp;rows = await </span><br />
<span class="f_CodeExample">// Add a method for mass deletion of items in the Posts app and specify the criterion for selecting items and the number of records in one deletion request. &nbsp; </span><br />
<span class="f_CodeExample">Context.fields.postsapp.app.batch().delete().delete().where((f) =&gt; f.__createdAt.lt(new Datetime('2024-01-01'))).size(100).from(0).all();</span><br />
<span class="f_CodeExample"> &nbsp; &nbsp;} </span><br />
<span class="f_CodeExample">while (rows &gt; 0) &nbsp; &nbsp;</span><br />
<span class="f_CodeExample">}</span></p>
<ol style="list-style-type:upper-roman" start="5">
<li value="5" class="p_Normal">Now, we need to create another button to delete entries in the <span style="font-weight: bold;">Comments</span> app in a similar way. We will delete items according to the same criteria: depending on their creation date, 100 pieces at a time.<br />
To do this, add the <span style="font-weight: bold;">Button</span> widget on the <span style="font-weight: bold;">Template</span> tab. &nbsp;Perform the same settings as for the <span style="font-weight: bold;">Delete Posts</span> button. When writing the script, use the code of the <span style="font-weight: bold;">Comments</span> app variable.</li><li value="6" class="p_Normal">Save and publish the updates.</li></ol>
<p class="p_Normal">Now, the module settings will display buttons for deleting items from the <span style="font-weight: bold;">Posts</span> and <span style="font-weight: bold;">Comments</span> apps depending on their creation date.</p>
<div class="bottom-nav">
<a id="prev-link" class="topic__navi_prev" href="app-data-in-scripts.html">
<span class="bottom-nav__arrow bottom-nav__arrow--prev"></span> <span
class="bottom-nav__link">app-data-in-scripts.html</span>
</a>
<a id="next-link" class="topic__navi_next" href="system_objects.html">
<span class="bottom-nav__link">system_objects.html</span> <span
class="bottom-nav__arrow bottom-nav__arrow--next"></span>
</a>
</div>
<!-- добавляет на страницу строку блок Была ли статья полезной? -->
<div class="feedback" id="feedback"><div class="feedback-help"><span><b>Was this helpful?</b></span><form action="" method="POST" class="feedback-form" id="feedback-form"><div class="feedback__popup feedback__popup-response" id="feedback__popup_thx" style="display: none;">Thanks for your feedback!</div><div class="feedback__popup" id="feedback__popup_why" style="display: none;"><div class="feedback__popup-header">Please specify why:</div><input type="radio" name="category" id="bad_recommendation" value="bad_recommendation"><label for="bad_recommendation">Recommendations did not help me</label><input type="radio" name="category" id="difficult_text" value="difficult_text"><label for="difficult_text">Article is hard to understand</label><input type="radio" name="category" id="no_answer" value="no_answer"><label for="no_answer">Didn`t answer my question</label><input type="radio" name="category" id="bad_header" value="bad_header"><label for="bad_header">Content does not match the topic</label><input type="radio" name="category" id="other_reason" value="other_reason"><label for="other_reason">Other</label></div><div class="feedback__popup" id="feedback__popup-other" style="display: none;"><div class="feedback__popup-header">How we can improve it?</div><textarea class="feedback__textarea" name="other" id=""></textarea><input type="submit" class="feedback__other-btn" value="Submit"></div><div class="feedback-form__btn-group"><input type="radio" name="useful" id="feedback__useful_yes" value="true"><label for="feedback__useful_yes"><img src="like.svg" class="small-img" alt="like"><spanclass="feedback-form__btn-group_yes-btn">Yes</spanclass="feedback-form__btn-group_yes-btn"></label><input type="radio" name="useful" id="feedback__useful_no" value="false"><label for="feedback__useful_no"><img src="dislike.svg" class="small-img" alt="dislike"><spanclass="feedback-form__btn-group_no-btn">No</spanclass="feedback-form__btn-group_no-btn"></label></div><select name="category"><option disabled="">Please specify why</option><option value="bad_recommendation" selected="">Recommendations did not help me</option><option value="difficult_text">Article is hard to understand</option><option value="no_answer">Didn`t answer my question</option><option value="bad_header">Content does not match the topic</option><option value="other_reason">Other</option></select><input type="submit"></form></div><div class="found_typo"><p style="margin: 0px; margin-top: 16px !important;"><span><b>Found a typo?</b></span> Select it and press <i>Ctrl+Enter</i> to send us feedback</p></div></div>
</section>
</div>
<aside class="article__sidebar" style="display:none">
<input type="checkbox" />
<div class="article__arrow"></div>
<div class="table-of-contents elma365-right" id="toc2Content">
<h3 class="h3-toc">In this topic</h3>
<nav id="toc2"></nav>
</div>
</aside>
</div>
</article>
</main>
<footer class="footer">
<div class="footer-container">
<div class="footer-mobile">
<ul class="footer-mobile__list"><li><a href="https://brix365.com/en/" target="_blank">BRIX</a></li><li><a href="https://tssdk.brix365.com/en/latest/" target="_blank">SDK</a></li><li><a href="https://api.brix365.com/en/" target="_blank">API</a></li></ul><ul class="footer-mobile__list"><li><a href="https://brix365.com/en/help/platform/get-trial.html">Platform</a></li><li><a href="https://brix365.com/en/help/ecm/ecm-functions.html">ECM</a></li><li><a href="https://brix365.com/en/help/service/service-functions.html">Service</a></li><li><a href="https://brix365.com/en/help/projects/projects-functions.html">Projects</a></li></ul>
</div>
<div class="footer-wrap">
<div><span class="mobile-question-popup">Send feedback</span><form method="POST" action class="question__popup question-xs" id="question__popup"><div class="question-wrap"><span class="close"></span><span class="title">Ask a question</span><label for="help_question" style="display: none;"></label><textarea name="help_question" id="help_question"></textarea><input type="submit" value="Send"></div></form><div class="hidden fade-in question-success-xs">Sent</div></div>
<div class="footer-flex-b">
<span class="footer-copy">&copy; 2025 BRIX</span>
<ul class="footer-list">
<li class="footer-item">
<a href="#" class="arrow-top" style="display: block;"></a>
</li>
</ul>
</div>
</div>
</div>
</footer>
<iframe name="hmnavigation" style="display:none!important"></iframe>
<script src="./jquery-ui.js"></script>
<!--script src="//cdn.jsdelivr.net/npm/featherlight@1.7.14/release/featherlight.min.js" type="text/javascript" charset="utf-8"></script-->
<script src="./jquery.tocify.min.js"></script>
<script src="./TypoReporter.min.js"></script>
<script src="./google-search.js"></script>
<script src="./main.js"></script>
<script type="text/javascript">
HMInitToggle('TOGGLE0186A1','hm.type','dropdown','hm.state','0');
HMInitToggle('TOGGLE0186A2','hm.type','dropdown','hm.state','0');
</script>
</body>
</html>