Numeric attribute 0 is returned as undefined by tm1Ui.dimensionElements

element
canvas

#1

In my measure dimension each element has a numeric attribute called Editable which will either be 0 or 1.
I retrieve these dimension elements using $tm1Ui.dimensionElements and get all the elements as expected in the response array, and if the attribute is 1 it is set as such in the response array. But if the attribute is 0 it is simply not defined in the response.

response[idx].Attributes['Editable']

Is this a bug?


#2

Hi @Roland,

That is the standard behavior as TM1’s REST API does not return them either.


Paul


#3

@plim Why does the API not simply return 0?


#4

Hi @Roland,

IBM should have the official answer on that. Though, from a size perspective, it makes the response smaller.

How are you planning to use that attribute? You maybe able to create a condition that checks for it and its value instead.


Paul


#5

@plim This is a can of worms. Consider:

var editable = response[idx].Attributes['Editable']);
if (editable) {
    //do some action
}

The above code will work because the attribute value 0 will be returned as undefined and 1 will be returned as "1"(string), thus the boolean evaluation will behave as expected with 1 evaluating as true and 0 evaluating as false. If $tm1Ui.dimensionElements ever changes and returns "0"(string) for the attribute value 0 then the variable editable will always evaluate as true in a boolean context.

To safeguard against this I do:

var editable = 1 == response[idx].Attributes['Editable']);

I guess not everyone is aware of this trap though.


#6

Hi @Roland,

You should be able to actually re-write the above as:

var editable = response[idx].Attributes['Editable']);
if (editable != undefined && editable == 1) {
    //do some action
}


Paul