Crash Course 101
10 modules
5 weeks

Using ID in URL

Click to copy

How to create hierarchical data structure


Using global variables is not able to cover all cases - we will not be able to give a link to the selected entry. After all, the value of a variable is stored only in the browser tab where it was set. To solve this problem, it is possible to write the necessary information directly into the URL and pass the exact link to a specific element.

Let's see how to do this with a specific example. Let's make it so that in the table with the list of countries, double-clicking on any row opens information only about those cities that belong to this country. This will allow us to implement navigation with a hierarchical data structure when you can navigate from a parent element to its child elements.

Page settings

First of all, you need to change the address of the page with the table of cities. To do this, open the settings of the corresponding menu item and specify the :id variable in the URL address.

Next, you need to set up navigation, which should not only go to the specified page but also add the ID parameter to the URL. To do this, let's go back to the table with the list of countries and set up actions on the onRowDoubleClick trigger. Now, double-clicking on a row in the table will navigate to the page, the address of which will contain the ID of the selected record.

Business process to get ID from URL

The next step is to get the given ID from the URL. This feature may be needed in a variety of business processes, so the best solution would be to create a separate function for it. It can be created in the corresponding tab of the web applications section. At the same time, unlike the business processes that were previously created for the backend, it will not be executed on the server but directly on the device of the user who launched it.

In business process we use the following blocks:

  • Get Current Page, to get the current URL.
  • Split string, to break the URL into separate blocks by selecting “/” as the delimiter.
  • For a specific page, we could immediately specify the desired String from the resulting array by its index. But the business process is universal and can be used for a URL of a different structure, so it's better to complicate the logic a bit. Let's check the number of String elements in the array after splitting using the Array size block.
  • Using the Subtract block, subtract 3 from the resulting amount (our element is the second from the end, and the index numbering itself starts from 0).
  • Pass the calculated value as an index to the Array Element block to get the required String from the array.
  • Make the final conversion of String to Integer.

And now we just have to use the value from the created business process in GET requests to get data into the table.

Was this article helpful?
Still looking for an answer?
Join the Community