Principal Name


#1

I understand that in tm1-ui-subnm the tm1-default-element has to be the principal Name of the element.

How can I convert an element to the principal name in Canvas.

I tried using $tm1Ui.dimensionElement

$scope.principalName = function (myDim, myAlias) {
    console.log("xxx")        $tm1Ui.dimensionElement('dev', myDim, myAlias).then(function(data){
        $scope.page.princName=data
        console.log($scope.page.princName)
    })
}; 

It always comes out as undefined


#2

Hi @mmacdonnell,

Which version of Canvas are you using?

Also, how are you triggering the above principalName() function?

The dimensionElement() function should be alright to receive an element or an alias. Can you check the documentation if you have this:

And when the function is invoked, it will return an array with a single object:

image

From which you can grab the principal name via data[0].Name property.


Paul


#3

Hi Paul,

I’m using version 2.0.7 of Canvas:

I’ve tried invoking dimension Element from a tm1-ui-subnm:

<tm1-ui-subnm
                                       tm1-instance="dev"
                                       tm1-dimension="Org Unit"
                                       tm1-server-mode="true"
                                       tm1-default-element=principalName("DetailsMeasure",'61023367')
                                       ng-model="model"
                                       >
                                    </tm1-ui-subnm>

Note: the subnm works apart from the default.

The above didn’t spit out any of my console.log commands in the js, so I also tried to use an ng-mouseover.
This invokes the js and I can see my parameters are getting through correctly, but it returns undefined
I’ve tried with the alias and also hardcoding the principal name (as in the example above)

To test my syntax I replaced dimensionElement with dimensionAttributes, using just the instance and dimension parameters and it returned an array as expected


#4

Hi @mmacdonnell,

That is because the tm1-default-element is expecting a string / text and not a function. Although the function returns a string, it still has to be pass the value properly into tm1-default-element for it to accept the result.

Normally, a string can be passed by enclosing them within {{ < variable here > }}. However it is not advisable to do this with functions, which can often lead to lots of $digest cycles being involved.

Going back to your case, where is the source of the value 61023367?

Ideally, you can use a variable instead for which you can update based on an event on your page. So the above will look like:

<tm1-ui-subnm
   tm1-instance="dev"
   tm1-dimension="Org Unit"
   tm1-server-mode="true"
   tm1-default-element="{{values.defaultUnit}}"
   ng-model="model"
   >
</tm1-ui-subnm>

On your source, if it is a dropdown for example, you can add an ng-change in there, and trigger the $tm1Ui.dimensionElement function to update the variable we have used:

<select  ... ng-model="values.orgUnitAlias" ng-change="updateDefaultOrgUnit(values.orgUnitAlias)"></select>

And finally, the code that will be called to grab the principal element name:

$scope.updateDefaultOrgUnit = function(orgUnitAlias){
		$tm1Ui.dimensionElement('dev', 'Org Unit', orgUnitAlias).then(function(data){			
			$scope.values.defaultUnit = data[0].Name;
		});
	};

The above is just an example. If you are using SELECT, an easier alternative is to just use SUBNM with the pure dropdown mode enabled. As the ng-model of the SUBNM should always give you the Principal Name of the selected element.


Paul