Learning Objectives
-
Master the use of code blocks to generate arrays + subprocesses to execute multiple times and generate multiple pieces of data.
-
Grasp the usage of process parameter assignment, and learn to pass the unique identifier (such as Record ID) of a record in the main process to the process parameters of the subprocess, so as to accurately obtain this record in the subprocess.
-
Learn to use Packaged Business Process (PBP) to generate multiple pieces of data by executing multiple times based on numerical fields.
Scenario Case
MEGA Company needs to uniformly manage the entire life cycle of event device. Each piece of device must leave a record in the system from the time of purchase. Every time devices are purchased, a new purchase record is added to the "device Purchase" worksheet to record the device model, quantity and other information of this purchase.
At the same time, they hope to achieve:
-
For each device purchase record, there is a "Device Archiving" button. After clicking this button, the corresponding number of new device files can be automatically generated in the device file according to the quantity purchased this time.
-
The device code of these new files must be consistent with the existing device code rules and realize auto-increment. For example: the device type code of the Wireless Amplifier is Speaker. The codes of the existing 2 Wireless Amplifiers are Speaker-1 and Speaker-2 respectively. After purchasing 3 new Wireless Amplifiers, it is hoped that 3 device files can be generated with one click, and the codes are Speaker-3, Speaker-4 and Speaker-5 respectively.
Operation Guide
Requirement Analysis
If the requirement is to generate multiple records, the following methods can be adopted:
-
Realize by [Add Record Node - Add Multiple Records Based on batch data] (hereinafter referred to as Batch Add Node); add multiple records at a time and execute once.
-
Realize by [Add Record - Add a new Record] (hereinafter referred to as Single Add Node) + [Subprocess] or [Packaged Business Process (PBP)], add one record at a time and execute multiple times.
However, there is an additional requirement: when each device file is added, the device code field must be consistent with the existing device code rules and realize auto-increment.
This means that when each device record is added, the workflow must separately judge the existing device quantity and generate a new code according to the rules to fill in. Therefore, it is not suitable to directly use the Batch Add Node, but the second method is applicable: use the Single Add Node, and execute it multiple times with Subprocess or PBP, and generate the device code separately each time it is executed.
The ideas of implementing via Subprocess and Packaged Business Process (PBP) are introduced below respectively.
Array + Subprocess to Generate Multiple Data
Code Block to Generate Array
The data source of the subprocess must be multiple data objects, which can be multiple records or array objects. There is only one record in the device purchase record, so we can choose to construct an array object to achieve it. Through the Code Block node, an array of corresponding length can be generated according to the purchased quantity of the device.
We can generate code through AI:
Code example:
// Receive the members of the input object
const number = input.number;
// Generate the corresponding arrayconst result
Array = Array.from({ length: number }, (_, index) => index + 1);
// Output the result to the output object
output = { result: resultArray };
After writing the code, click Test, input a number, and check whether the Output parameters meet the expectations; click Save after the test is correct.
Get Multiple Data from Array Object
-
Use Get Multiple Data - Get Array Object to obtain the array generated by the code block.
Array Object Enters Subprocess
-
Add a Subprocess node and select the code block array object as the data source of the subprocess.
-
Select the sequential execution method to prevent duplicate serial numbers due to concurrent calculation when the device code serial number increments.
Process Parameter Assignment
Add process parameters to the subprocess, name it Device_po_id and pass the Record ID or other unique value fields of the device purchase record in the main process. The purpose is to find the corresponding device purchase record in the subprocess according to this unique value field.
Obtain device Purchase Record and device Type in Subprocess
-
In order to obtain information such as the device type on the purchase record, add a Get Single Data node to query the corresponding device purchase record in the main process according to the incoming process parameter [Device_po_id]. The purchase record is associated with the device type, so the corresponding device type record can be obtained through [Get Single Data - Get Associated Records].
Summarize the Total Number of device Types and Calculate the Current Serial Number
-
Use Rollup node to summarize the number of records in the device worksheet where the device type is the same as the device type in the device purchase record and add 1 to the number as the serial number of the next record to realize the increment of the device code serial number.
Add device File and Fill in Corresponding Code + Serial Number
-
Add a new Device record, and configure the corresponding fields using the information from the device purchase worksheet obtained through the input parameters.
-
Back to the main process (Device Archiving button), update the Archive Status of Device Purchase record to Archived.
PBP Generates Multiple Data Based on Numerical Fields
In addition to using Subprocess to realize this requirement, we can also use Packaged Business Process (PBP) to complete it.
In terms of capabilities, PBP is very similar to Subprocess. Both extract a section of reusable process logic for other processes to call multiple times; the main differences are:
-
Different data sources: Subprocess is usually bound to a certain data source (such as worksheet records), and the main process sends multiple records for processing one by one; while PBP does not depend on specific data worksheet,it only needs to predefine input parameters, and any process, page button or external system can call it with parameters as needed.
-
More flexible execution method: PBP can not only be called cyclically based on multiple data objects like Subprocess, but also the main process can pass in a specific numerical parameter, and control the number of cycles or calculations in PBP according to this numerical value, which is more suitable for being reused as a general "tool capability" in multiple scenarios.
In this scenario, we can determine the number of executions of the Packaged Business Process (PBP) based on the device purchase quantity.
Add Packaged Business Process Node
-
Enter the workflow configuration page of the Device Archiving button, add a Packaged Business Process node, and create a new Packaged Business Process (PBP).
-
Set the input parameters of PBP, named Purchase ID, to receive the Record ID in the device Purchase worksheet.
-
Select the newly created PBP as the business process, select Multiple Executions as the execution method, and the number of executions is based on the purchase quantity in the device purchase record. Select Sequential Execution as the execution method for multiple business processes, because the serial number must be incremented sequentially to avoid generating duplicate serial numbers concurrently. Fill in the Record ID of the purchase record into the PBP input parameters.
-
In the Packaged Business Process, in order to obtain information such as the device type on the purchase record, add a Get Single Record node to query the corresponding device purchase record in the main process according to the Record ID. Since the purchase record is associated with a single device type, the corresponding device type record can be obtained through [Get Single Record - Get associated Records].
Summarize the Total Number of device Types and Calculate the Current Serial Number
-
Summarize the number of records in the device worksheet where the device type is the same as the device type in the purchase order, and add 1 to the number as the serial number of the next record.
Add device File and Fill in Corresponding Code
-
Add a new device file record, and configure the corresponding fields using the information from the device purchase worksheet obtained through the input parameters.
-
Back to the main process (Device Archiving button), update the Archive Status of Device Purchase record to Archived.
Implementation Effect
Select the first purchase order and click the Device Archiving button. 5 new records of Wireless Amplifier are added to the device worksheet, and the codes start from 3.
Hands-on Practice
Now, click the "Open the Practice App" button in the upper right corner of the page to access the hands-on application designed for this course, and start practicing!