Checking if an Attribute Exists (essentially an “AttributeExists” Function)

Have you ever looked for a TM1 function that checks if an attribute exists, something like say “AttributeExists” or “AttrExists”. Well there isn’t one. But, don’t dispair, here is a quick method you can use to do exactly that in a Turbo Integrator process.

I am writing a TI to build and then subsequently update a dimension. Right up front I am defining a bunch of variables, like the dimension name. Then I am using the DimensionExists function to check of the dimension actually exists, and if not, creating it using DimensionCreate. Finally I want to check if there is an attribute on that dimension and if not, create it.

Attribute Exists Code Example

Then I have a little bit of code that checks to see if an attribute exists and if not, then it is added. The code is:

## Check if Attribute Exists and if not, add it
DimName = 'Product'
AttrName = 'Name';
IF ( DIMIX ('}Element_Attributes_' | DimName, AttrName ) = 0);
    ATTRINSERT ( DimName,'', AttrName ,'s');
ENDIF;

What this is doing is defining the dimension and attribute. Then it uses a DIMIX to check if the attribute exists in the Control Object for the Element Attributes for the Dimension. Then if it the answer is no (a Zero), then it inserts the attribute into the dimension using ATTRINSERT. Note the type of attrubute is defined as String, Alias or Numeric (S, A or N).

It could also be paired with an ATTRDELETE function to test if an attribute exists and if so, then to delete it. That code would look like this:

## Check if Attribute Exists and if so, delete it
DimName = 'Product'
AttrName = 'Name';
IF ( DIMIX ('}Element_Attributes_' | DimName, AttrName ) > 0 );
    ATTRDELETE ( DimName, AttrName );
ENDIF;

So this is a really easy way of checking if an attribute exists and then adding it to a dimension without being able to use the non-existent AttributeExists, AttrExists function!

  • This field is for validation purposes and should be left unchanged.

Leave a Reply

Your email address will not be published. Required fields are marked *

Log In