Skip to content

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.

  1. Open any dataset and navigate to the “Client Script” tab, as shown in the figure below.

    Image

  2. Click on the “Client Script” tab to access the code panel.

    Image

  3. Check the “Client Script” checkbox to activate the code panel.

  4. The Client Script provides several language options, including Javascript, AlaSQL, and D3.

  5. 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;

Image

  1. Click the “Preview” button to check the output of the JSON data, as shown in the figure below.

    Image

  2. Click “Update” to save the changes.


Client script using Alasql

  1. For Client script using the Alasql, select the Alasql options form dropdown as shown in figure below:

    Image

  2. Go to Client Script Tab & write/ paste your required script. (For this example, you can use refer below given Note)

Image

  1. Now Click on Update Button to apply the client script on Dataset.

  2. Now Go to Dashboard Section from hamburger menu.

  3. Create a Dashboard. Click here to see how to create dashboard.

  4. Add Table Widget into blank dashboard.

  5. Fill the below details as given:-

    Dataset: salesClientScript.ds [Use the ds where you added the client script]

  6. Go to Client Script Tab & Check the Client Script checkbox.

    Image

  7. Click on Preview & Update Matadata button respectively.

    Image

  8. Thensimply click on the preview button to see the final output of the data. as shown in the figure below:

    Image