Obtiene una lista a partir de un objeto JSON
[en] See below an example on how to build a lambda process to display the end user's card list in the app landing screen. 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 display the end user's card list in the app home screen. To do so, first you need to execute the Entrust call API to request the list of cards. The Entrust Digital Card solution securely provides digital card features to mobile applications. The API returns a JSON object that you need to parse. With the information obtained from the parsed JSON, you need to populate the array that will display the card list in the app home screen.
[en] Prerequisites
[en] For this example, take into account that you need to use three elements::
[en] The Entrust call API, which should be available in your environment when you create the process. To learn how to use call APIs, refer to Use Call APIs. If you don't see the call API enabled in your environment, contact the Mobile Product team.
[en] A lambda process that validates the user and password. The process to obtain the user's cards will be invoked from the process that validates the user and password to display the user's cards in the landing screen once the identity of the user has been verified. To learn how to create the login validation process, refer to Create a Lambda Process.
[en] The home screen where the cards will be displayed.
Nota
[en] Even though the last two items are not indispensable to create the lambda process, you should have them defined beforehand to complete the process configuration.
[en] How to Create a Lambda Process to Display the End User's Card List
[en] Go to Branch Edition > Processes.
[en] In the Lambda processes tab, click + New lambda process. The lambdas editor opens.
[en] In the Process Basic Info tab that opens by default, complete information about the process you are building.
[en] In the Name field, add a name to the lambda process that represents its functionality. For this example, enter Get card list from JSON.
[en] In the Description field, add a short text that explains the aim of the logic created. If there is a call API included in the process, add its name to the process description to easily track it. For this example, enterParses Entrust JSON to obtain end user's card list and display it in the landing screen.
[en] In the Tags field, add keywords for you and your team to easily group processes according to their functionality. For this example, set cards.
[en] Now, you can start dragging blocks from the left panel into the canvas to build your process. Follow the instructions below to execute the call API to request the list of cards, parse the JSON object returned by the call API and populate the array to display the list of cards in the landing screen.
[en] Execute call API to request the list of cards
[en] First, set the call API function that obtains the user's card list as a variable. To do so, follow these steps:
[en] Go to the blocks list and find the Variables block category or type variables in the search bar
[en] Click to open the category and click Make a Variable... to create a new one.
[en] Set the variable name and click Ok to finish the creation process. For this example, enter entrust_GET_CARDS.
[en] Then, find the set variable to block, drop it into the canvas and connect it to the on start block.
[en] Select the entrust_GET_CARDS variable from the variables drop-down menu.
[en] Then, find the API function that obtains the user's cards. For this example, search for the entrust digital card get cards include not provisioned cards block. Drag the API function block into the canvas and connect it to the set variable to block.
[en] Finally, set the block value as true. To do so, go to the blocks list and find the Text block category or type text in the search bar.
[en] Click to open the category and see the blocks available. Drag the " " block into the canvas and connect it to the value slot of the entrust digital card get cards include not provisioned cards block. Complete the text block with true.
[en] Best Practice
[en] Setting the API function as a variable is considered a good practice as it improves the readability of the lambda process and allows you to easily reuse the function within the lambda process as many times as you may need.
[en] Then, to execute the Entrust call API to obtain the JSON with the user's card list, follow these steps:
[en] Go to the blocks list and find the Call APIs block category or type call apis in the search bar.
[en] Click to open the category and see the APIs available. Drag the execute call api block into the canvas and connect it to the on start block below the set variable to block.
[en] Attach the entrust_GET_CARDS variable to the block value slot. The JSON returned by the call API is stored in register 290 and has the following structure:
[en] Parse JSON object returned by the call API
[en] First, create a new JSON object from the user's card list returned by the call API function in register 290 and set it as a variable. To do so, follow these steps:
[en] Go to the blocks list and find the Variables block category or type variables in the search bar.
[en] Click to open the category and see the blocks available and click Make a Variable... to create a new one.
[en] Enter the variable name and click Ok to finish the creation process. For this example, enter jsonCardObject.
[en] Then, find the set variable to block that already contains the create json object from serialized string block within its value slot in the JSON block category, drop it into the canvas and connect it to the on start block below the execute call api block.
[en] Select the jsonCardObject variable previously created from the variables dropdown.
[en] Finally, complete the block value slot with the register where the JSON string is saved. To do so, go to the blocks list and find the Registers block category or type registers in the search bar.
[en] Click to open the category and see the blocks available. Drag the register text block into the canvas and connect it to the create json object from serialized string block.
[en] Complete the block with the register 290.
[en] Then, obtain the information from the CARDS list object and set it as a variable. To do so, follow these steps:
[en] Go to the blocks list and find the Variables block category or type variables in the search bar.
[en] Click to open the category and see the blocks available and click Make a Variable... to create a new one.
[en] Set the variable name and click Ok to finish the creation process. For this example, entercardListObject.
[en] Then, find the set variable to block, drop it into the canvas and connect it to the on start block below the previous set variable to block.
[en] Select the cardListObject variable from the variables dropdown.
[en] Then, find the block that obtains the cards list. For this example, search for the get json object list for block. Drag the block into the canvas and connect it to the set variable to block.
[en] Complete the first value slot with the jsonCardObject variable.
[en] Finally, complete the block text value with the list object name. For this example, set CARDS.
[en] Now, you can obtain the information provided for each card in the list. To do so, follow these steps:
[en] Go to the blocks list and find the Loops block category or type loops in the search bar.
[en] Click to open the category and see the functions available. Drag the for element block into the canvas and connect it to the on start block below the last set variable to 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 card list.
[en] Set a new variable with the name cardRow and attach it to the first value slot of the for element block.
[en] Complete the second value slot of the for element block with the cardListObject variable.
[en] Then, go through each row of the list to extract its information. To do so, follow these steps:
[en] To go through the cardInfo sublist within each card list, set a new variable with the name cardInfoObject and attach it to the for element block.
[en] Go to the JSON block category in the blocks list on the left and drag the get json object for block into the canvas.
[en] Attach it to the cardInfoObject variable and complete the first block value with the cardRow variable and the second block value with the desired row. For this example, complete the second value with cardInfo.
[en] To obtain the card ID from the cardInfo sublist, set a new variable with the name cardId and attach it to the for element block below the previous set variable to block.
[en] Go to the JSON block category in the blocks list on the left and drag the get string for block into the canvas.
[en] Attach it to the cardId variable and complete the first block value with the cardInfoObject variable and the second block value with the desired row. For this example, complete the text value with issuerCardId.
[en] To obtain the card last four digits from the cardInfo sublist, set a new variable with the name cardLastFour and attach it to the for element block below the previous set variable to block.
[en] Go to the JSON block category in the blocks menu on the left and drag the get string for block into the canvas.
Sugerencia
[en] Given that the structure of this block and the previous one is the same, you may duplicate the last set variable to block configured and replace its values with the new ones to speed up the building process.
[en] Attach it to the cardLastFour variable and complete the first block value with the cardInfoObject variable and the second block value with the desired row. For this example, complete the text value with lastDigits.
[en] To obtain the card number from each card list, set a new variable with the name cardNumber and attach it to the for element block below the previous set variable to block.
[en] Go to the JSON block category in the blocks menu on the left and drag the get string for block into the canvas.
Sugerencia
[en] Given that the structure of this block and the previous one is the same, you may duplicate the last set variable to block configured and replace its values with the new ones to speed up the building process.
[en] Attach it to the cardNumber variable and complete the first block value with the cardRow variable and the second block value with the desired row. For this example, complete the text value with id.
[en] To obtain the card's first six numbers, set a new variable with the name cardBIN and attach it to the for element block below the previous set variable to block.
[en] Go to the Text block category in the blocks menu on the left and drag the substring of block into the canvas.
[en] Attach it to the cardBIN variable and complete the first block value with the cardNumber variable, and the second and third value slots with the length of the string you want to save. For this example, set from 0 to 6.
[en] Populate array to display the list of cards in the landing screen
[en] Once you have extracted the required information, set a new variable to store the information in a new list and add it to the array table that contains the cards list. To do so, follow these steps:
[en] Go to the List block category in the blocks menu on the left and drag the set [text list] to array block into the canvas.
[en] Attach it to the for element block below the previous set variable to block.
[en] Select the list items you want to include in the array. For this example, complete the cardID and the cardLastFour variables into the first two slots, the third slot with the text Active, and the final slot with the cardNumber variable.
[en] Finally, go to the blocks menu and find the Arrays block category in the blocks menu on the left and drag the add row to array table block into the canvas.
[en] Attach it to the for element block below the set [text list] to array block.
[en] Complete the first value slot with the row number where you want to store the list within the array table. For this example, enter 5 and the second value slot with the cardInfoList variable.
[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.
[en] Click Save in the actions bar.
[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 a Next block within the lambda process that validates the user and password when logging in, to display the user's cards in the landing screen.