Updating indicator result with data from $.get (or $.ajax)
I'm trying to update an indicator widget with data that is returned from an ajax call, currently fired off from the 'processresult' event. The Ajax call returns, but the indicator data is not updated (on the display anyway).
Is there some way of forcing the widget to update (or redraw) itself from the Javascript API?
var build_date = 'Updating';
widget.on('processresult', function(w, e) {
e.result.title.text = 'Last update time';
e.result.value.text = 'Updating...';
var url = 'https://sisenseinstance/api/elasticubes/servers/LocalHost/production-animal-performance-daily/lastBuildTime';
$.ajax({
type: 'GET',
url: url,
success: function(data) {
console.log('got build time');
var d = data.replace('/Date(','').replace(')/','').replace("\\",'').replace(')\\/','').replace('"','');
build_date = new Date(parseInt(d, 10));
e.result.value.text = build_date;
// w.redraw();
}
});
});
-
Hi Tim,
Few tips to get you started:
- Sisense's doesn't let you convert the event handlers to act as async functions. That means that if you're sending an ajax request from within an event, you can't know the exact time that the response code will be triggered.
- Therefore, it would be highly advised to try and avoid async calls from the event handlers where possible (trust me on this one, it frequently causes un expected behavior and it is a nightmare to debug it)
- You can use the global variable "prism" to get a lot of the data that you need so it will save you a lot of requests. Specificaly, to your case - run prism.activeDashboard.datasource to get a list of all the datasources that the dashboard is using and the "lastBuildTime" property to get their build time for you to use in your code (there are many other ways to get to that list by the way)
With the above in mind, if all you're looking to achive is to have a label widget on the dashboard that present the last build time then you can easily creat a custom table in the cube with a single field and a single value that stores the currentTimestamp as its value.
Then use a BloX widget (or the old school Smart Label plugin) to pull that data and present it as you wish on the dashboard.
I hope it helped and feel free to reach out if you have any questions. We're always happy to help (:
Ravid
Please sign in to leave a comment.
Comments
1 comment