Create Dataset using Client Script
What is Client Script?
Client scripts allow the system to run defined language on the client (web browser) when client-based events occur, such as when a form loads, after form submission, or when a field changes value. Well-designed client scripts can reduce the amount of time it takes to complete a form and improve the user experience.
Client script using Javascript
Steps to Convert Nested JSON to JSON Data Using Client Script.
-
Open any dataset and navigate to the “Client Script” tab, as shown in the figure below.
-
Click on the “Client Script” tab to access the code panel.
-
Check the “Client Script” checkbox to activate the code panel.
-
The Client Script provides several language options, including Javascript, AlaSQL, and D3.
-
By default, the Javascript option is selected. Keep it set to Javascript and enter the following code, as shown in the figure below:
Code Example:
/* Retrieve data from the aivData variable */
const resultArray = [];
aivData.forEach(item => {
const features = item.features;
features.forEach(feature => {
const properties = feature.properties;
const events = properties.event_set__all;
events.forEach(event => {
const resultObj = {
"neighborhood__slug": properties.neighborhood__slug,
"venue": properties.venue,
"neighborhood__neighborhood": properties.neighborhood__neighborhood,
"address": properties.address,
"slug": properties.slug,
"category__category": event.category__category,
"title": event.title,
"cost": event.cost,
"description": event.description,
"id": feature.id
};
resultArray.push(resultObj);
});
});
});
return resultArray;
-
Click the “Preview” button to check the output of the JSON data, as shown in the figure below.
-
Click “Update” to save the changes.
Client script using Alasql
-
For Client script using the Alasql, select the Alasql options form dropdown as shown in figure below:
-
Go to Client Script Tab & write/ paste your required script. (For this example, you can use refer below given Note)
-
Now Click on Update Button to apply the client script on Dataset.
-
Now Go to Dashboard Section from hamburger menu.
-
Create a Dashboard. Click here to see how to create dashboard.
-
Add Table Widget into blank dashboard.
-
Fill the below details as given:-
Dataset: salesClientScript.ds [Use the ds where you added the client script]
-
Go to Client Script Tab & Check the
Client Script
checkbox. -
Click on Preview & Update Matadata button respectively.
-
Thensimply click on the preview button to see the final output of the data. as shown in the figure below: