ToolJet/docs/versioned_docs/version-2.33.0/how-to/use-url-params-on-load.md
Akshay 2d08d889de
Release: Community changes (v2.34.0) (#9226)
* add custom resolvers info and editable row selection info (#9057)

* fix system requirements icon

* add auth info for webhooks and fix casing

* add regex custom validation info (#9068)

* [docs]: Marketplace 1.7 updates (#9085)

* [docs] Amazon redshift plugin

* make minor improvements

* add and update docs for marketplace 1.7

* update order of plugins in overview to match sidebar

* create new version

---------

Co-authored-by: Shubhendra <withshubh@gmail.com>

* add the latest version in the versions.json file (#9094)

* [docs]: Update PDF component (#9088)

* update PDF component

* merged with develop and added changes to the new version

* update docs favicon: (#9118)

* [docs] SSO revamp (#9031)

* add method to set default language

* update image settings through custom css and update screenshots for getting started and tooljet concepts (#9158)

* fix read documentation button

* fix formatting for setup icons (#9172)

* fix sidebar link for aws lambda

* Update static media (#9175)

* updated the screenshots

* reduced the gif size

* reverted the package.json file

* edited the zoomed in images and replaced some gifs with screenshots

* removed one gif

* update static media

* update file names

* update toolbar

* fix file names

* fix: dynamodb img path

* update media for org management dashboard

* fix: casing and formatting

* update workspace constant media

* update media in workspace settings and github

* update github sso

* minor change to github sso docs

* minor fix

* update google sso

* change includeCurrentVersion flag to false

---------

Co-authored-by: Asjad Ahmed Khan <iitasjad2001@gmail.com>
Co-authored-by: Asjad Ahmed Khan <60435499+2001asjad@users.noreply.github.com>
Co-authored-by: Karan Rathod <karan.altcampus@gmail.com>

* Feature: Engagespot plugin (#9012)

* feat(plugins): added engagespot plugin

* feat(docs): added engagespot plugin docs

* chore(engagespot-plugin): revised copywritings

* Feature: Databricks data source (#9174)

* plugin-created

* Databricks integration

* icon, error handling

* removed unrelated changes from marketplace and frontend package-lock.json removed runAsync and maxRows timeouts pending

* timeout implementation

* socket timeout and error handling

* resolve comments

* resolve comments2

* solved render issue test connection improvements

* solved undefined error

* fix TJDB not null value fail for is operation (#9055)

* fix TJDB not null value fail for is operation

* handling not null and null case insenstive values

* Support for marketplace plugin deploy on render preview app (#9221)

* Fix for marketplace error on render preview app

* add marketplace build command

* Adding new workflow for building marketplace plugin

* removed render app creation

* [:docs] Add documentation for Databricks plugin (#9224)

* add docs for databricks

* update databricks docs

* update docs

* remove ref to clusters

* bump to v2.34.0

* Fixed data source cypress failure (#9227)

* updated spec with required text

* updated mongodb and import spec

* updated import spec

---------

Co-authored-by: Karan Rathod <karan.altcampus@gmail.com>
Co-authored-by: Adish M <44204658+adishM98@users.noreply.github.com>
Co-authored-by: Midhun G S <gsmithun4@gmail.com>
Co-authored-by: Shubhendra <withshubh@gmail.com>
Co-authored-by: Aman Regu <amanregu@gmail.com>
Co-authored-by: Asjad Ahmed Khan <iitasjad2001@gmail.com>
Co-authored-by: Asjad Ahmed Khan <60435499+2001asjad@users.noreply.github.com>
Co-authored-by: Jobin Jose <129726530+jobin-logidots@users.noreply.github.com>
Co-authored-by: Syed Mohammad Akhtar Rizvi <85864291+ShazanRizvi@users.noreply.github.com>
Co-authored-by: blank0537 <111295371+blank0537@users.noreply.github.com>
Co-authored-by: Mekhla Asopa <59684099+Mekhla-Asopa@users.noreply.github.com>
2024-03-29 19:13:26 +05:30

7.1 KiB

id title
use-url-params-on-load Use URL Parameters on page load

In this guide, we will learn how to use URL parameters at the time of page load. The URL parameters are used to pass data from one page to another. Currently, we can add URL parameters in the following ways:

If a page is opened with URL parameters, you can access them using the {{globals.urlparams}}. This object contains all the URL parameters as key-value pairs and specific parameters can be accessed using the key like {{globals.urlparams.<parameter_name>}}.

Let's take a look at an example below to understand how to use URL parameters on page load.

Using URL parameters on page load to execute REST API queries

Create two pages, Home and Dashboard. When a new app is created, a page named Home is created by default. Create a new page named Dashboard from the Pages menu in the left sidebar.

Use URL Parameters on page load

Home and Dashboard Pages

Add a form component to the Home page. The form component will have a text input fields and a button. The text input field will be used to enter the name and the button will be used to navigate to the Dashboard page. Let's name the text input field as email and the button as Submit.

Use URL Parameters on page load

Select the button and add the event On click, select action Switch page, and then select the page Dashboard. Here, we will also find the option to add URL parameters. Add the URL parameter email and set the value to {{components.form1.data.textinput1.value}}. This will pass the value of the email input field to the Dashboard page as a URL parameter.

Use URL Parameters on page load

Now, on clicking the Submit button, the Dashboard page will be opened with the URL parameter email containing the value of the email input field. You can open the Inspector on left sidebar and navigate to the URL Params under the globals to check the URL parameters.

Use URL Parameters on page load

Queries and binding data

In the Dashboard page, add two table components. We will be loading the data from two different REST API queries on these tables.

Query 1: Get products

  • Create a new REST API query and name it as products. We will be using a mock REST API to fetch the data. The URL for the REST API is https://fakestoreapi.com/products. Run the query and check the preview to see the returned data.
  • Go to the table1 properties, set the value of table data to {{queries.products.data}}. This will bind the data returned from the REST API query to the table.
Use URL Parameters on page load

Query 2: Get user details

  • Create a new REST API query and name it as users. We will be using a mock REST API to fetch the data. The URL for the REST API is https://jsonplaceholder.typicode.com/users. Run the query and check the preview to see the returned data.
  • Go to the table2 properties, set the value of table data to {{queries.users.data}}. This will bind the data returned from the REST API query to the table.
Use URL Parameters on page load

Query 3: JavaScript code to use URL parameters

  • Create a new JavaScript code query and name it as urlparams. We will be using this query to access the URL parameters and to check if the email parameter is present in the URL, then trigger the REST API queries.
function waitForURLParams(timeout) {  // Wait for URL parameters to be available
  const check = resolve => {  // Check if URL parameters are available
    if (location.search.length > 0) resolve();  // URL parameters are available
    else setTimeout(_ => check(resolve), timeout);  // Check again after a timeout
  }
  return new Promise(check); // Return a promise that resolves when URL parameters are available
}

async function checkAndRunQuery(timeout) { // Check if URL parameters are available and run the REST API queries
  await waitForURLParams(timeout);  // Wait for URL parameters to be available
  const urlParams = new URLSearchParams(window.location.search);  // Get URL parameters

  if (urlParams.get('email')) {  // Check if email parameter is present in the URL
    await actions.runQuery('products');  // Run the REST API query to get products
    await actions.runQuery('users');  // Run the REST API query to get user details
  } 
  else {
    alert('URL param not found');  // Alert if email parameter is not present in the URL
  }
}

checkAndRunQuery(5000);  // Check if URL parameters are available and run the REST API queries after a timeout of 5 seconds

Dashboard page event handler

  • Finally, go to the Pages menu in the left sidebar and open the menu for the Dashboard page.
  • Select the option to add Event handler and add a new On page load, select the option to Run query and select the query urlparams. This will trigger the JavaScript code query to check if the email parameter is present in the URL and then run the REST API queries whenever the Dashboard page is loaded.
Use URL Parameters on page load

Now, whenever the user will enter the email in the Home page and click the Submit button, the Dashboard page will be opened with the URL parameter email containing the value of the email input field. The JavaScript code query will check if the email parameter is present in the URL and then run the REST API queries to fetch the data. The data will be displayed in the tables on the Dashboard page.