Store $tm1Ui.cellGet value into variable


#1

Hi All

Sorry for the basic question. How do I store the value returned by a $tm1Ui.cellGet command into a variable?

Thanks
David


#2

Just assign it to scope inside $tm1Ui service function:

$scope.yourVariableName = data;
 //see what is data structure
console.log(data);

Have a look at help page to see example how to work with $tm1Ui service.

On a page it might be
{{ yourVariableName.Value }}


#3

Thanks Eugene. I didn’t find the help page to be all that clear on how to identify the value.

The next problem is how I use this variable. One of our pages can be viewed independently, or via another report. When it’s coming from another report we’re passing variables through the URL. I want the receiving page to use either the variable passed through OR if no variable is passed through, then the value retrieved from the $tm1Ui service. I can’t seem to do this in javascript, however.

I’m retrieving the system value like this:

$tm1Ui.cellGet('veolia','SYS Settings','WAS Reporting Year-Month','String').then(function(data){
        $scope.systemPeriod = data; 
   });

Then I want to add an IF statement to check if a value has come through via the URL, and if not make another variable equal to the value returned by the $tm1Ui service:

if ( _expression_ ) {
    $scope.Period = $scope.systemPeriod
} else {
    $scope.Period = _urlValue_
};

I have been able to get to my desired result by using ng-if in the HTML, but is there any way this can be done in javascript?

Thanks
David


#4

you still can do it inside $tm1Ui.cellGet( ).

$tm1Ui.cellGet('veolia','SYS Settings','WAS Reporting Year-Month','String').then(function(data){
    if ( 1>2 ) {
      $scope.Period = $scope.systemPeriod;
    } else {
     $scope.Period = _urlValue_;
    };
   });

But you need understand how Anularjs services work. $tm1Ui.cellGet is a promise. So when data is ready, you will get it. before you get it you need make sure all your conditions are ready for evaluation, or you may run cellGet when your variable changes.

Also you can wrap $tm1Ui.cellGet into function:

$scope.someFuncton(somePeriod){
   $tm1Ui.cellGet('dev','GL','Actual','2016',somePeriod, 'Revenue').then(function(data){
         $scope.glData = data; 
   });
};

and later you can call this function when you need (For exanple, using ng-click)


#5

but if you are using :/id on a page, i would rather add

//in the beginning of controller
    $scope.someFunction(){
       if( $stateParams.yourId ){
           $scope.yourPeriod =  $stateParams.yourId;
        } else {
          $tm1Ui.cellGet('someInstance','SomeCube','firstElement','secondElement').then( function(data){
             $scope.yourPeriod = data.Value;
          });
        };
    };

//call the function
$scope.someFunction();

Is it what you are looking for?


#6

Hi Eugene

Thanks for your help with this. I have been able to use just ng-ifs to get the same result and avoid the issue you mentioned of the variable getting re-evaluated when I don’t want it to.

Cheers
David