Trigger Data Queries using JavaScript
The DATAQUERY._data-query-name_.trigger()
method provides a straightforward way to retrieve data from a predefined
endpoint/query. This method is particularly useful in event-driven architectures where specific actions or data
retrievals need to be triggered upon certain events. It simplifies the process of fetching data and integrating it into
your application.
How to Use It
To utilize the DATAQUERY._data-query-name_.trigger()
method in your custom JavaScript code, follow these steps:
Create a New Data Query:
- Click on
+ New
to create a new data query. - Name your query, e.g.,
triggerdetail
.
- Click on
Set the Query Parameters:
- Set the
Run Query
option to "Every time variables change".
- Set the
Define Input Parameters:
- Add an input parameter named
Keywords
. - Provide a test value for
Keywords
to facilitate testing.
- Add an input parameter named
Write the JavaScript Code:
- Use the
DATAQUERY.getComments.trigger()
method within an asynchronous function to handle the data retrieval. - Handle any errors that might occur during the execution.
try {
output = await DATAQUERY.getComments.trigger();
} catch (error) {
output = error;
}
}- Use the
Test and Save Your Query:
- Use the provided test value to run your query and verify the output.
- Save the query to make it available for use within your application.
How to Obtain It
To obtain the DATAQUERY._data-query-name_.trigger()
method of a data query, follow these steps:
Access the Data Queries Interface:
- Navigate to the Data Queries section of your development environment.
Create and Configure the Query:
- Create a query, to which you want to trigger the method later. click
test
. On the right-hand side of Response, there is aShow
button for trigger method for this dataquery from JS
- Create a query, to which you want to trigger the method later. click
Use the Provided Code:
- Implement the JavaScript code provided to trigger the
getComments
query and handle the retrieved data.
- Implement the JavaScript code provided to trigger the