When trying to getDataConnectorByID, TypeError: Cannot read property 'getFile' of undefined

I am trying to get the last modified time of a data connector (which is an excel sheet) and place it in a label on the dashboard. I have it running on the Ready event but cannot get the code to run past the “getDataConnectorByID” step. I get the below error in the debugger window:

TypeError: Cannot read property ‘getFile’ of undefined

Any help would be appreciated.

debugger;
var connectorId = "55c0b85a-2e29-49cb-831f-4885bbd18450";
connectorId = connectorId.toLowerCase(); 

var dataConnectorService = new dundas.entities.DataConnectorService();

**var getConnectorPromise = dataConnectorService.getDataConnectorById(connectorId);**

// If successfully retrieved the Connector.
getConnectorPromise.done(
  	function(lastmodifiedvalue)
  	{
      // Success    
      label1.labelText = lastmodifiedvalue.lastModifiedTime;
   	}
);
// If failed to get Connector.
getConnectorPromise.fail(
  	function(failValue)
  	{
      // Fail    
      label1.labelText = failValue.responseText;
   	}
);

Added the ** ** on the line it is failing for emphasis.

Hi @christopher.simpson,

Give this a go - you shoull request service objects using the .getService() method.

(function anonymous(image1,e
) {
debugger;
var connectorId = "900b7e59-00a0-4f44-8e5d-129a17e2e61e";
connectorId = connectorId.toLowerCase(); 

var dataConnectorService = this.getService("DataConnectorService");

var getConnectorPromise = dataConnectorService.getDataConnectorById(connectorId);

// If successfully retrieved the Connector.
getConnectorPromise.done(
  	function(lastmodifiedvalue)
  	{
      // Success    
      label1.labelText = lastmodifiedvalue.lastModifiedTime;
   	}
);
// If failed to get Connector.
getConnectorPromise.fail(
  	function(failValue)
  	{
      // Fail    
      label1.labelText = failValue.responseText;
   	}
);
})
1 Like

Thanks for the quick response Jeff, that was the fix!

For my own learning, what is different between the getService vs what the documentation talks about?

I admit I suck at javascript, so if it is a stupid question, refer me to Google :slight_smile:

Morning @christopher.simpson,

I think in general you’re just kinda looking in the wrong place but you got most of it. The purpose of a document like this is to simply show that a constructor for the DataConnector object exists but doesn’t aim to show you how to work with it. You’ll see the same on many parts of the documentation that discusses an (init) object.

In general Dundas BI is built around a service model and you’ll see that this.getService() is core to almost everything. Look how many areas of the application that you can access through service. It’s a massive entry point.

https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/Service/cindex.html%3FTocPath%3DAPI%20Reference|dundas|Service|_____0

1 Like

Thanks Jeff, I will use going forward!