Get Last Updated Date and Time for Data Cube

Hello,

I’m fairly new to scripting but I’m just wondering if someone can steer me in the right path.
I have my data cube set to warehouse mode, on a specific dashboard that uses this cube I want to display a dynamic date as to when this cube was last updated. I figured I can pull this via script and put it in a text box.

From the two links
https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/entities/DataCubeService/Methods/getDataCubeById.html

https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/entities/DataCube/Properties/lastModifiedTime.html
I got as var as getting the service

It looks like I have to define a variable to get the DataCubeService and then from this get the cube by ID, but I’m afraid this is where my lack of programming knowledge stops.

Here’s my code that I have so far:
var dataCubeService = this.getService(“DataCubeService”);

var temp = new Date(dataCubeService.getDataCubeById(“036553ff-8428-42af-9d1b-99d9a52027d7”).lastModifiedTime);

var dateStr = temp.getFullYear().toString() +
temp.getMonth().toString() +
temp.getDate().toString() +
temp.getHours().toString() +
temp.getMinutes().toString() +
temp.getSeconds().toString();

Can anyone help me out?

Thanks in advance!

Hi Daniel

getCubeById does not return a value, instead it returns a Promise. You can Google to find all the details about Promises and callbacks, but I warn you, it can get complicated. The basic idea is that you get a Promise which is like a placeholder for something that JavaScript is going to get at some point later. This helps the script continue doing other things whilst it is waiting for the cube to be fetched, in this case.

To access the cube when it does arrive, you can use the .done functionality. This runs the code inside it, using the cube that has been retrieved when it arrives. I would go for something like the following, and place the code you need inside the function.

dataCubeService.getDataCubeById(“036553ff-8428-42af-9d1b-99d9a52027d7”).done(
  function(cube)
	{
		var temp = cube.lastModifiedTime;
		var dateStr = temp.getFullYear().toString() +
		temp.getMonth().toString() +
		temp.getDate().toString() +
		temp.getHours().toString() +
		temp.getMinutes().toString() +
		temp.getSeconds().toString();
		console.log(dateStr);
            //stick it in a label etc.
	}
   )

Things do get messy if there is an error retrieving the cube, if you want a particular execution order or have multiple Promises.

Hope this points you in the right direction

1 Like

Hi Daniel,
Were you able to make the label display the last update time? It will be helpful if you can share your knowledge with us. I am looking for a similar solution for my case as well.

Hello,

I think the question you’re asking is the same as another one where I provided an answer: