cancel
Showing results for 
Search instead for 
Did you mean: 
Liliia_DevX
Sisense Team Member
Sisense Team Member

How to Add a TimeStamp to a Widget Title

This article provides directions on how to add a timestamp to a widget title using JavaScript.  This could be useful in cases where a user needs to calculate specific metrics in a Live Data model (the script also works with widgets based on ElastiCube). For this solution to work, it is important to know the last time and date of the browser page refresh. Please refer to the example below:

Before:

Liliia_DevX_0-1689766904022.png

After: 

Liliia_DevX_1-1689766951759.png

How to Use the Script?

1. Open a widget in Edit mode by clicking the pencil icon. 

2. Click the three dots menu and choose "Edit Script."

3. Copy and paste the below script into the "Edit Script" section and press "Save."

 

 

 

widget.on("initialized", function() {
    let title = widget.title.split(' (timestamp:')[0]
    let dateAdded = false
    if (!dateAdded) {
        var today = new Date();
        var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate() + ' ' + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
        console.log(widget.title + date)
        widget.title = title + ' (timestamp: ' + date + ')';
        dateAdded = true
    }
});

 

 

 

4. Click "Apply" in the widget edit mode and refresh the dashboard page.

As a result, you will get the current date and time appended to the widget title. If you refresh the page, the time will be refreshed accordingly. 

Please feel free to adjust this example script to your needs and share your solutions with us!

We hope this helps! 

Disclaimer: Please note that this blog post contains one possible custom workaround solution for users with similar use cases. We cannot guarantee that the custom code solution described in this post will work in every scenario or with every Sisense software version. As such, we strongly advise users to test solutions in their own environment prior to deploying them to ensure that the solutions proffered function as desired in their environment. For the avoidance of doubt, the content of this blog post is provided to you “as-is” and without warranty of any kind, express, implied, or otherwise, including without limitation any warranty of security and or fitness for a particular purpose. The workaround solution described in this post incorporates custom coding, which is outside the Sisense product development environment and is, therefore, not covered by Sisense warranty and support services.

Version history
Last update:
‎02-13-2024 12:18 PM
Updated by:
Community Toolbox

Recommended quick links to assist you in optimizing your community experience:

Developers Group:

Product Feedback Forum:

Need additional support?:

Submit a Support Request

The Legal Stuff

Have a question about the Sisense Community?

Email [email protected]

Share this page: