Wiki

Scale Your Enterprise

User Tools

Site Tools


bw2:looping_tool

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
bw2:looping_tool [2020/12/15 12:22]
akoehler created
bw2:looping_tool [2024/09/24 15:39] (current)
dlee [Loop Variables]
Line 1: Line 1:
-====== Introduction (Looping Tool) ====== 
  
-This page describes the use of the “looping” tool in Bizweaver.+====== Loop Tool ======
  
-====== The Looping Tool ======+The Bizweaver “looping” tool is used to process a series of objects in succession while optionally performing other actions on each object. Typical use cases include:
  
-The Bizweaver “looping” tool is a mechanism used to process a series of objects in succession while, optionally, performing other actions on each object. Typical use cases include: +  * Processing a set of records generated from SQL Query
- +
-  * Processing a set of records generated from an SQL Command: Reader+
   * Processing multiple input files in one workflow cycle   * Processing multiple input files in one workflow cycle
-  * Processing records from a File Reader step into an SQL table +  * Processing records from a File Reader 
-  * Processing records from an SQL Command: Reader step into a File Writer: Custom String step+
  
 The logic of the looping process is straightforward. The logic of the looping process is straightforward.
Line 22: Line 19:
  
 <WRAP center round important> <WRAP center round important>
-**In the following examples, the name of the Loop and LoopEnd are similar. However, the names of the looping steps are used only to assist the developer. The only requirements are that for each “Loop” step there must be a corresponding “LoopEnd” stepand that the step name is unique.**+**In the following examples, the name of the Loop and LoopEnd are similar, however, the names of the looping steps are used only to assist the developer. The only requirements are that for each “Loop” stepthere must be a corresponding “LoopEnd” step and that the step name is unique.**
 </WRAP> </WRAP>
  
Line 30: Line 27:
 This example illustrates the use of looping to process a set of records from an SQL Command: Reader step. In this case, we are using Customer Contact Persons in SAP Business One. We will send an email to each contact. This example illustrates the use of looping to process a set of records from an SQL Command: Reader step. In this case, we are using Customer Contact Persons in SAP Business One. We will send an email to each contact.
  
-{{  :bw:loopimage1.png?576x106  }}+{{ :bw2:bizweaverlooptool1.png |}}
  
-  - The first step is to create a list of contacts. In this example, we use the internal code assigned to each contact by SAP Business One. From this we get a list of code values. \\ {{  :bw:loopimage2.png?384x181  }} +  - The first step is to create a list of contacts. In this example, we use the internal code assigned to each contact by SAP Business One. From thiswe get a list of code values. \\ {{ :bw2:bizweaverlooptool2.png |}} 
-  - A loop is started using the list from step 1 as input. (Linked Object). \\ {{  :bw:loopimage3.png?384x135  }} +  - A loop is started using the list from step 1 as input. (Linked Object). \\ {{ :bw2:bizweaverlooptool3.png |}} 
-  A second SQL Command: Reader step is used to get the details for the first contact record. +  A second SQL Command: Reader step is used to get the first contact record's details
-      - The code from the list is used to get the specific information for the contact. \\ {{  :bw:loopimage4.png?384x194  }}+      - The code from the list is used to get the specific information for the contact. \\ {{ :bw2:bizweaverlooptool4.png |}}
   - The e-mail is created.   - The e-mail is created.
-      - The recipient’s e-mail address is taken from the details in step 3. \\ {{  :bw:loopimage5.png?384x127  }} +      - The recipient’s e-mail address is taken from the details in step 3. \\ {{ :bw2:bizweaverlooptool5.png |}} 
-  - The application now checks to see if there are any additional records in the list passed into the loop that have not been processed.+  - The application now checks to see if there are any additional records in the list passed into the loop that has not been processed.
       - If an unprocessed record is found, steps 3 and 4 are executed for the next record.       - If an unprocessed record is found, steps 3 and 4 are executed for the next record.
       - If no records remain to be processed, the loop ends, and the process continues to the next workflow step.       - If no records remain to be processed, the loop ends, and the process continues to the next workflow step.
  
 <WRAP center round info> <WRAP center round info>
-In this example, the list is created for a single value. The details needed for processing are then retrieved for each record inside the loop. Another approach is to get all the information needed in the first SQL step. The second SQL step inside the loop is then not required since all the information is available. There are no specific rules about which approach to use. **However**, attempting to feeding very large blocks of data into the loop can potentially cause failure of the workflow.+In this example, the list is created for a single value. The details needed for processing are then retrieved for each record inside the loop. Another approach is to get all the information needed in the first SQL step. The second SQL step inside the loop is then not required since all the information is available. There are no specific rules about which approach to use. **However**, attempting to feed very large blocks of data into the loop can potentially cause the workflow's failure.
 </WRAP> </WRAP>
  
Line 49: Line 46:
 ====== Loop-Within-Loop Example ====== ====== Loop-Within-Loop Example ======
  
-This example illustrates a more complicated set of looping cycles; a loop within a loop. The first loop processes a list of files from a File Operations: Get step. The second loop, which is inside the first loop, processes the records in each file and posts them into an SQL table. This type of loop processing is very common.+This example illustrates a more complicated set of looping cycles; a loop within a loop. The first loop processes a list of files from a File Operations: Get step. The second loop, which is inside the first loop, processes each file's records and posts them into an SQL table. This type of loop processing is very common.
  
-{{  :bw:loopimage6.png?576x126  }}+{{ :bw2:bizweaverlooptool6.png |}}
  
-  - The first step is to create a “virtual” list of files to be processed. This is done using **File Operations: Get.** In this sample, we are processing any .csv file starting with “test.” \\ {{  :bw:loopimage7.png?384x172  }}+  - The first step is to create a “virtual” list of files to be processed. This is done using **File Operations: Get.** In this sample, we are processing any .csv file starting with “test.” \\ {{ :bw2:bizweaverlooptool7.png |}}
   - The initial loop processes the list of files created in step 1.   - The initial loop processes the list of files created in step 1.
       - The input is selected from the “Linked Object” drop-down list.       - The input is selected from the “Linked Object” drop-down list.
       - If a file is found, the workflow proceeds to the next step (3).       - If a file is found, the workflow proceeds to the next step (3).
-      - If no files are found to process, the workflow proceeds to the end of the loop (step 7) and, in this case, ends. \\ {{  :bw:loopimage8.png?384x136  }}+      - If no files are found to process, the workflow proceeds to the end of the loop (step 7) and, in this case, ends. \\ {{ :bw2:bizweaverlooptool8.png |}}
   - A File Reader step processes the file presented from step 2.   - A File Reader step processes the file presented from step 2.
       - The file is referenced using a variable as shown.       - The file is referenced using a variable as shown.
-      - The output of the File Reader is a virtual list of the records in the file. \\ {{  :bw:loopimage9.png?384x319  +      - The output of the File Reader is a virtual list of the records in the file. \\ {{ :bw2:bizweaverlooptool9.png |}}
- }}+
   - A second loop processes the list of records created in step 3.   - A second loop processes the list of records created in step 3.
       - The input is selected from the “Linked Object” drop-down list.       - The input is selected from the “Linked Object” drop-down list.
       - If a record is found, the workflow proceeds to the next step (5).       - If a record is found, the workflow proceeds to the next step (5).
-      - If no records are found, the workflow proceeds to the end of the loop (step 6). \\ {{  :bw:loopimage10.png?384x133  }}+      - If no records are found, the workflow proceeds to the end of the loop (step 6). \\ {{ :bw2:bizweaverlooptool10.png |}}
   - The record from the previous step is inserted into an SQL table.   - The record from the previous step is inserted into an SQL table.
-      - The input values are referenced by Bizweaver variables. \\ {{  :bw:loopimage11.png?384x230  }}+      - The input values are referenced by Bizweaver variables. \\ {{ :bw2:bizweaverlooptool11.png |}}
   - At this Loop End, the application tests to see if any records from the virtual list have not been processed.   - At this Loop End, the application tests to see if any records from the virtual list have not been processed.
       - If unprocessed records are found, the process returns to the starting point of the current loop (step 4)       - If unprocessed records are found, the process returns to the starting point of the current loop (step 4)
Line 73: Line 69:
   - At this Loop End, the application tests to see if any files from the virtual list have not been processed.   - At this Loop End, the application tests to see if any files from the virtual list have not been processed.
       - If unprocessed files are found, the process returns to the starting point of the current loop (step 4)       - If unprocessed files are found, the process returns to the starting point of the current loop (step 4)
-      - If no unprocessed files are found, the process continues to the next step, which is the end of the workflow.+      - If no unprocessed files are found, the process continues to the next step, which is the workflow's end.
 ====== Conditional Looping ====== ====== Conditional Looping ======
  
Line 82: Line 78:
 </WRAP> </WRAP>
  
 +In this example, we want to drop out of the loop when records are no longer available for processing. The difference here is that we are checking for valid records in blocks of 50 records.
 +
 +{{ :bw2:bizweaverlooptool12.png |}}
  
-The following example workflow illustrates how conditional looping works. This example is for demonstration purposes but can serve as foundation to understand the concept.+  - Two variables are used: MaxDocEntry and RecsRemain. The variables are defined and initialized in the “Variables_Init” step. \\ {{ :bw2:bizweaverlooptool13.png |}} \\ MaxDocEntry starts at 0 so the following tests begin with the lowest record ID (DocEntry). RecsRemain starts at 1 to indicate that records remain to process. 
 +  - Loop_Counter begins the loop process. This is where the looping condition is established. \\ {{ :bw2:bizweaverlooptool14.png |}} {{ :bw2:bizweaverlooptool15.png |}} \\ The condition to continue processing (looping) is that the “RecsRemain” variable = 1. 
 +  - The SQLCommand_checkMaxRec step determines the last DocEntry value in the current block of 50 records. This value will be used in the next step. \\ {{ :bw2:bizweaverlooptool17.png |}} 
 +  - The SQLCommand_checkRemainCount set determines whether records remain or not. \\ {{ :bw2:bizweaverlooptool18.png |}} \\ Note that the value used for “RecsRemain” is either 0 or a 1. 
 +  - The two variables established at the beginning of the workflow are updated. \\ {{ :bw2:bizweaverlooptool19.png |}} 
 +  - At this point, the difference between a “Linked Object” loop and a “Conditional Expression” loop comes into play. In a “Linked Object” loop, the process would check to see if another single record exists for processing. In this “Conditional Expression” loop, the process instead checks the value of the “RecsRemain” variable. The determination to continue looping is made based on this value. Once the “RecsRemain” variable value changes to 0, the loop ends.
  
-In this example, we want to drop out of the loop when records are no longer available for processing. The difference here is that we are checking for valid records in blocks of 50 records. Again, this for illustration only.+====== Loop Variables ======
  
-{{  :bw:loopimage12.png?576x61  }}+^ Name           ^ Description          ^ 
 +| StepMessage         | During a failure the reason for failure will be populated here| 
 +| StepStatus         | True or False        |
  
-  Two variables are used: MaxDocEntry and RecsRemain. The variables are defined and initialized in the “Variables_Init” step. \\ {{  :bw:loopimage13.png?420x220  }} \\ MaxDocEntry starts at 0 so the following tests begin with the lowest record ID (DocEntry). RecsRemain starts at 1 to indicate that records to remain to process. +---- 
-  Loop_Counter begins the loop process. This is where the looping condition is established. \\ {{  +**[[bizweaver:Home|Home]]**
- :bw:loopimage14.png?384x225  }} \\ The condition to continue processing (looping) is that the “RecsRemain” variable = 1. +
-  The SQLCommand_checkMaxRec step determines the last DocEntry value in the current block of 50 records. This value will be used in the next step. \\ {{  :bw:loopimage15.png?384x116  }} +
-  The SQLCommand_checkRemainCount set determines whether records remain or not. \\ {{  :bw:loopimage16.png?384x182  }} \\ Note that the value used for “RecsRemain” is either a 0 or a 1. +
-  - The two variables established at the beginning of the workflow are updated. \\ {{  :bw:loopimage17.png?384x203  }} +
-  - At this point the difference between a “Linked Object” loop and a “Conditional Expression” loop comes into play. In a “Linked Object” loop the process would check to see if another single record exists for processing. In this “Conditional Expression” loop the process instead checks the value of the “RecsRemain” variable. The determination to continue looping is made based on this value. Once the “RecsRemain” variable value changes to 0, the loop ends.+
bw2/looping_tool.1608052922.txt.gz · Last modified: 2020/12/15 12:22 by akoehler