How to get the time and status of cube build job

Hi, I want my dashboard to display the time and status (Ran to completion / Faulted …) of the cube build job, which the dashboard references.
I wrote the script below for the dashboard’s Ready script:

var metricSet1 = table1.metricSetBindings[0].dataResult.metricSet;
metricSet1.getAnalysisStructure().done(function (dataCube1) {
  filterRule = new dundas.scheduling.JobQueryFilterRule();
  filterRule.field = dundas.scheduling.JobQueryField.RELATED_ITEM_ID;
  filterRule.value = dataCube1.id;
  new dundas.scheduling.SchedulingService().queryJobs({filter: [filterRule]}).done(function (jobs) {
    console.log("jobs:", jobs);
    <to display the time and status of the job>
  });
});

But, I just got the error:

job/query/ (POST) error:
status:400 Bad Request
response message:The request is invalid.
exception message:
exception type:
stack trace:

Could someone tell me what’s wrong and how to modify the script?

Hello,

The first thing you can check is the metadata on the file itself.

You could try something like this:

window.dundas.context.getService("FileSystemService").getEntryById(table1.metricSetBindings[0].dataResult.metricSet.analysisStructureId).done(function (file) {

                    // Check for warehouse timestamp.
                    var warehouseTimestamp = $E(file).first(function (kvp) {
                        return kvp.key == dundas.constants.FILE_METADATA_CUBE_WAREHOUSE_TIMESTAMP;
                    });
                    if (warehouseTimestamp) {
                        var warehouseDate = Globalize.format(dundas.Utility.getUTCOffsettedDateTime(new Date(warehouseTimestamp.value)), "F");
                    }

                    // Check for timestamp.
                    var inMemoryTimestamp = $E(file).first(function (kvp) {
                        return kvp.key == dundas.constants.FILE_METADATA_CUBE_HYPERGRAPH_TIMESTAMP;
                    });
                    if (inMemoryTimestamp) {
                        var inMemoryDate = Globalize.format(dundas.Utility.getUTCOffsettedDateTime(new Date(hypergraphTimestamp.value)), "F");
                    }
});

However this metadata isn’t always available, so an alternative is to query for it using the new method added in v9 called queryDataCubeInfos:

window.dundas.context.getService("DataCubeService").queryDataCubeInfos().done(function (dataCubeInfos) {
    // Look at the data cube infos here, one will have a .id that matches table1.metricSetBindings[0].dataResult.metricSet.analysisStructureId
});

This one will have additional information on the job status, last run date etc.

2 Likes

Thank you for your prompt answer!
I understand I can get cube’s info with “FileSystemService” (or with “DataCubeService” in v9).

Below is my dashboard’s updated Ready script:

dundas.context
  .getService("FileSystemService")
  .getEntryById(table1.metricSetBindings[0].dataResult.metricSet.analysisStructureId)
  .done(function (file) {
    // Check for timestamp.
    var storageType = file.metadata.first(function (kvp) {
      return kvp.key == dundas.constants.FILE_METADATA_CUBE_STORAGE_TYPE_KEY;
    });
    var timestamp;
    if (storageType.value == "1") {
      //// Warehouse
      timestamp = file.metadata.first(function (kvp) {
        return kvp.key == dundas.constants.FILE_METADATA_CUBE_WAREHOUSE_TIMESTAMP;
      });
    } else if (storageType.value == "2") {
      //// In-Memory
      timestamp = file.metadata.first(function (kvp) {
        return kvp.key == dundas.constants.FILE_METADATA_CUBE_HYPERGRAPH_TIMESTAMP;
      });
    }
    var datetimeString = Globalize.format(dundas.Utility.getUTCOffsettedDateTime(new Date(timestamp.value)), "F");
    // Display datetime on label
    dateTimeLabel.labelText = "Last update: " + datetimeString;
  });

By the way, can I get the result of build job status (Ran to completion / Faulted / …) with “FileSystemService” or “DataCubeService” ?
I looked into the structure of data cube gotten with “FileSystemService”, but found no info about build job status.
About “DataCubeService”, I’ll try it after version up to v9…

Unfortunately the file system service metadata check does not include those kinds of details. The good news is the v9 data cube service method does.

So if you upgrade you’ll have all that information :slight_smile:

Thank you for you precious info about DataCubeService!
I’ve decided to upgreade to v9 in a few days.

And I’ll show the final version of my script in this thread after implementing it. :smiley:

1 Like

I’ve upgraded Dundas BI to v9,
and by using “DataCubeService” I’ve successfully implemented it!

The following is the final script:

var metricSet1 = table1.metricSetBindings[0].dataResult.metricSet;
metricSet1.getAnalysisStructure().done(function (dataCube1) {
dundas.context
.getService(“DataCubeService”)
.queryDataCubeInfos()
.done(function (dataCubeInfos) {
var dataCubeInfo1 = dataCubeInfos.first(function (dataCubeInfo) {
return dataCubeInfo.id == dataCube1.id;
});
var lastRunInfo = dataCubeInfo1.job.lastRunInfo;
var datetimeString = Globalize.format(new Date(lastRunInfo.startTime), “F”);
dateTimeLabel.labelText = "Last update: " + datetimeString;
if (lastRunInfo.result !== “RanToCompletion”) { // if not successful
dateTimeLabel.labelText =
dateTimeLabel.labelText + “\n” + “(The last build job was not successful. )”;
dateTimeLabel.fontColor = new dundas.controls.Color(0xff0000, 0xff); // red color
}
});

Thank you!

2 Likes