Skip to main content

Veritran Docs

Recorre un array

[en] 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.

[en] 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.

[en] Prerequisites

[en] For this example, take into account that you need to use two elements:

  • [en] 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.

  • [en] The screen where the fixed-term deposits information is displayed.

Nota

[en] Even though the screen is not indispensable to create the lambda process, you should have it defined beforehand to complete the process configuration.

[en] 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
  1. [en] Go to Branch Edition > Processes.

  2. [en] In the Lambda processes tab, click + New lambda process. The lambdas editor opens.

  3. [en] In the Process Basic Info tab that opens by default, complete the information about the process you are building.

    1. [en] 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.

    2. [en] 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.

    3. [en] In the Tags field, add keywords for you and your team to easily group processes according to their functionality. For this example, enter deposits.

  4. [en] 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.

[en] Execute transaction to obtain user's list of fixed-term deposits
  1. [en] First, set the transaction that returns the user's list of fixed-term deposits as a variable. To do so, follow these steps:

    array_use_case_-_trx_variable_and_exec.gif
    1. [en] Go to the blocks list and find the Variables block category or type variables in the search bar.

    2. [en] Click to open the category and click Make a Variable... to create a new one.

    3. [en] Set the variable name and click Ok to finish the creation process. For this example, enter TRX_GET_FIXED_TERM.

    4. [en] Then, find the set variable to block, drop it into the canvas and connect it to the on start block.

    5. [en] Select the TRX_GET_FIXED_TERM variable from the variables drop-down menu.

    6. [en] 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.

    [en] Best Practice

    [en] 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.

  2. [en] Then, to execute the transaction, go to the list of blocks and find the Transactions block category or type transactions in the search bar.

  3. [en] 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.

  4. [en] 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.

[en] Go through array table to obtain deposit's currency type and amount, and add them up
  1. [en] 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:

    1. [en] Go to the blocks list and find the the Loops block category or type loops in the search bar.

      array_use_case_-_set_for_element.gif
    2. [en] 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.

    3. [en] Set a new variable with the name row and attach it to the first value slot of the for element block.

    4. [en] 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.

    5. [en] Then, go to the blocks list and find the the Branch block category or type branch in the search bar.

      array_use_case_-_set_if_then_else.gif
    6. [en] 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.

    7. [en] Drag the (" ") = (" ") comparison block from the Branch block category into the canvas and connect it to the if then else block value slot.

    8. [en] Drag the get value at block from the List category into the canvas and connect it to the comparison block first value slot.

    9. [en] 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.

    10. [en] 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.

    11. [en] 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:

      array_use_case_-_set_change_if_ARS.gif
      1. [en] 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.

      2. [en] Set a new variable with the name fixedTermsARS and attach it to the change by block first slot.

      3. [en] Enter 1 in the change by block second slot to add one fixed-term deposit to the count if the condition previously met is set.

      4. [en] 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.

      5. [en] Set a new variable with the name amountARS and attach it to the change by block first slot.

      6. [en] Drag the parse to number block from the Text block category into the canvas and attach it to the change by block second slot.

      7. [en] Drag the get value at block from the List category into the canvas and connect it to the parse to number block value slot.

      8. [en] 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.

    12. [en] 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:

      1. [en] Go to the blocks list and find Branch block category or type branch in the search bar.

        Sugerencia

        [en] 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.

        array_use_case_-_set_change_if_USD.gif
      2. [en] 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.

      3. [en] Drag the (" ") = (" ") comparison block from the Branch block category into the canvas and connect it to the if then block value slot.

      4. [en] 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.

      5. [en] 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.

    13. [en] 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:

      1. [en] 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.

      2. [en] Set a new variable with the name fixedTermsUSD and attach it to the change by block first slot.

      3. [en] Enter 1 in the change by block second slot to add one fixed-term deposit to the count if the condition previously met is set.

      4. [en] 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.

      5. [en] Set a new variable with the name amountUSD and attach it to the change by block first slot.

      6. [en] Drag the parse to number block from the Text block category into the canvas and attach it to the change by block second slot.

      7. [en] 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.

[en] Store the results obtained in registers to display on screen
  1. [en] 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:

    array_use_case_-_save_registers.gif
    1. [en] Go to the blocks list and find the Registers block category or type registers in the search bar.

    2. [en] 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.

    3. [en] 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.

    4. [en] Complete the save register with value block second value slot with the fixedTermsARS variable.

    5. [en] 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.

  2. [en] 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.

  3. [en] Click Save in the actions bar.

  4. [en] 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.