Go Through an Array Table
Below you can find an example on how to build a lambda process to go through a list of fixed-term deposits and calculate the accumulated amount of money for each currency type. Keep in mind that, since processes vary depending on the functionality you want to build and on the client's requirements, you may find different approaches on how to build a similar lambda process.
Consider the following scenario: you need to build a lambda process to go through an array containing a list of fixed-term deposits to calculate the accumulated amount of money of the deposits in dollars and the deposits in Argentine pesos. To do so, first, you need to execute a transaction to obtain the user's list of fixed-term deposits. Then, you need to go through every row of the array table to obtain each deposit's currency type and their amount. Finally, you need to add them up and store the number of deposits for each currency as well as the accumulated amount for each currency in different registers.
Prerequisites
For this example, take into account that you need to use two elements:
A transaction that returns the information on the user's fixed-term deposits. To learn how to create the transaction, refer to Create a Configurable Transaction.
The screen where the fixed-term deposits information is displayed.
Note
Even though the screen is not indispensable to create the lambda process, you should have it defined beforehand to complete the process configuration.
How to build a lambda process to go through a list of fixed-term deposits and calculate the accumulated amount of money for each currency type
Go to Branch Edition > Processes.
In the Lambda processes tab, click + New lambda process. The lambdas editor opens.
In the Process Basic Info tab that opens by default, complete the information about the process you are building.
In the Name field, add a name to the lambda process that represents its functionality. For this example, enter Get fixed-term deposits accumulated amount from array.
In the Description field, add a short text that explains the aim of the logic created. If there is a transaction included in the process, add its code to the process description to easily track it. For this example, enter Obtains fixed-term deposits accumulated amount of money in dollars and in Argentine pesos from array returned by trx 9995.
In the Tags field, add keywords for you and your team to easily group processes according to their functionality. For this example, enter deposits.
Now, you can start dragging blocks from the left panel into the canvas to build your process. Follow the instructions below to execute a transaction to obtain user's list of fixed-term deposits, go through the array table containing the user's list of fixed-term deposits to obtain their currency type and amount, and add them up and store the results obtained in registers to display on screen.
Execute transaction to obtain user's list of fixed-term deposits
First, set the transaction that returns the user's list of fixed-term deposits as a variable. To do so, follow these steps:
Go to the blocks list and find the Variables block category or type variables in the search bar.
Click to open the category and click Make a Variable... to create a new one.
Set the variable name and click Ok to finish the creation process. For this example, enter TRX_GET_FIXED_TERM.
Then, find the set variable to block, drop it into the canvas and connect it to the on start block.
Select the TRX_GET_FIXED_TERM variable from the variables drop-down menu.
Then, find the transaction created to obtain the user's list of fixed-term deposits. For this example, search for the transaction code 9995. Drag the transaction block into the canvas and connect it to the set variable to block.
Best Practice
Setting the transaction as a variable is considered a good practice as it improves the readability of the lambda process and allows you to easily reuse the transaction within the lambda process as many times as you need.
Then, to execute the transaction, go to the list of blocks and find the Transactions block category or type transactions in the search bar.
Click to open the category and see the blocks available. Then, drag the execute transaction block into the canvas and connect it to the on start block below the set variable to block.
Then, go to the blocks list and find the the TRX_GET_FIXED_TERM variable in the Variables block category and drag it into the execute transaction block.
Go through array table to obtain deposit's currency type and amount, and add them up
Once you have executed the transaction, you need to go through every row of the array table returned by the transaction to obtain each fixed-term deposit's details. Then, add up the number of deposits generated in Argentine pesos and in dollars, as well as the accumulated amount of money in each currency. To do so, follow these steps:
Go to the blocks list and find the the Loops block category or type loops in the search bar.
Click to open the category and see the blocks available. Drag the for element block into the canvas and connect it to the on start block below the execute transaction block. The loop block repeats the execution of the actions defined within its socket on every element of the list, in this case, on each deposit.
Set a new variable with the name row and attach it to the first value slot of the for element block.
Complete the second value slot of the for element block with an array table block and complete its value with the number of the required array. For this example, enter 1000, that is the transaction output containing the user's list of fixed-term deposits.
Then, go to the blocks list and find the the Branch block category or type branch in the search bar.
Click to open the category and see the blocks available. Drag the if then else conditional block into the canvas and connect it to the for element block. This block will allow you to go through the list and determine whether the fixed-term deposit is in Argentine pesos.
Drag the (" ") = (" ") comparison block from the Branch block category into the canvas and connect it to the if then else block value slot.
Drag the get value at block from the List category into the canvas and connect it to the comparison block first value slot.
Complete the block's first value slot with the row variable and the second value slot with the value that contains the currency type within the array. For this example, enter the value 2.
Complete the comparison block with the value that represents the currency type that you want to obtain. For this example, enter 80, that represents Argentine pesos.
Then, set the actions to be performed if the condition defined above is met, that is, if the fixed-term deposit is in Argentine pesos. To do so, follow these steps:
To obtain the number of deposits generated in Argentine pesos by adding up each deposit to the total number of deposits in that currency, drag the change by from the Variables block category into the canvas and attach it to the if then else conditional block first socket.
Set a new variable with the name fixedTermsARS and attach it to the change by block first slot.
Enter 1 in the change by block second slot to add one fixed-term deposit to the count if the condition previously set is met.
Then, you need to obtain the accumulated amount of money in Argentine pesos by adding each deposit's sum to the total. Drag another change by block from the Variables block category into the canvas and attach it to the if then else conditional block first socket below the previous change by block.
Set a new variable with the name amountARS and attach it to the change by block first slot.
Drag the parse to number block from the Text block category into the canvas and attach it to the change by block second slot.
Drag the get value at block from the List category into the canvas and connect it to the parse to number block value slot.
Complete the block's first value slot with the row variable and the second value slot with the value that contains the amount of Argentine pesos corresponding to the fixed-term deposit. For this example, enter the value 3.
Then, set an alternative condition to be met if the condition defined above is not satisfied. This condition will allow you to go through the list and determine if the fixed-term deposit is in dollars. To do so, follow these steps:
Go to the blocks list and find Branch block category or type branch in the search bar.
Tip
Given that the structure of the if then else block and the if then block is similar, you may duplicate the configured if then else block, remove the else clause socket, and replace its values with the ones defined in steps i and j to speed up the building process.
Click to open the category and see the blocks available. Drag the if then conditional block into the canvas and attach it to the if then else conditional block second socket.
Drag the (" ") = (" ") comparison block from the Branch block category into the canvas and connect it to the if then block value slot.
Drag the get value at block from the List category into the canvas and connect it to the comparison block first value slot. Complete the block's first value slot with the row variable and the second value slot with the value that contains the currency type within the array. For this example, enter the value 2.
Complete the comparison block with the value that represents the currency type that you want to obtain. For this example, enter 2, that represents dollars.
Then, set the actions to be performed if the new condition defined above is met, that is, if the fixed-term deposit is in dollars. To do so, follow these steps:
To add up the number of deposits generated in dollars by adding up each deposit to the total number of deposits in that currency, drag the change by from the Variables block category into the canvas and attach it to the if then conditional block socket.
Set a new variable with the name fixedTermsUSD and attach it to the change by block first slot.
Enter 1 in the change by block second slot to add one fixed-term deposit to the count if the condition previously set is met.
Then, to obtain the accumulated amount of money in dollars by adding each deposit's sum to the total, drag another change by block from the Variables block category into the canvas and attach it to the if then conditional block socket below the previous change by block.
Set a new variable with the name amountUSD and attach it to the change by block first slot.
Drag the parse to number block from the Text block category into the canvas and attach it to the change by block second slot.
Drag the get value at block from the List category into the canvas and connect it to the parse to number block value slot. Complete the block's first value slot with the row variable and the second value slot with the value that contains the amount of dollars corresponding to the fixed-term deposit. For this example, enter the value 3.
Store the results obtained in registers to display on screen
Finally, you need to store the results obtained in the previous steps into registers to be displayed on screen. To do so, follow these steps:
Go to the blocks list and find the Registers block category or type registers in the search bar.
Click to open the category and see the functions available. Drag the save register with value block into the canvas and connect it to the on start block below the if then else conditional block.
Define the register where the text will be stored. For this example, enter 2000. This register will then be added to the screen component where the value saved will be displayed.
Complete the save register with value block second value slot with the fixedTermsARS variable.
Repeat the previous steps to save registers 2001, 2002 and 2003 with the amountARS, fixedTermsUSD and amountUSD variables respectively. Given that the structure of these blocks and the previous one is the same, you may duplicate the first save register with value block and replace its values with the new ones to speed up the building process.
Before saving, you can run the process through the simulator to test the logic of the lambda process and ensure that it works as expected. This step is optional.
Click Save in the actions bar.
The Commit message modal opens, complete the description of the last changes made and, if applicable, the details of the JIRA ticket involved, then click Save again to finish the creation process. The lambda process created is ready to be invoked from the screen where the fixed-term deposits information is displayed.