AttrInsert TM1 Function: Use and Sytax
Sometimes we want to create a new attribute in TM1 dynamically during the execution of a TI process. This function allows us to do that and create either a string, a numeric or an alias attribute.
Syntax of AttrInsert
The syntax is:
AttrInsert ( DimName, PrevAttr, AttrName, Type );
- DimName – is the name of the dimension that you want to create an attribute on
- PrevAttr – is the name of the attribute immediately before the new attribute that you want to insert (so you get the attributes in the right order!).
- AttrName – is the name of the new attribute you are creating
- Type – is the type of attribute you are creating, either ‘N’, for numeric, ‘S’ for string or ‘A’ for an alias.
Example of AttrInsert
DimName = 'Employees';
AttrInsert ( DimName, 'Name', 'Status' , 'S' );
Here we have defined a variable called DimName with ‘Employees’ in the Prolog. Then lower down in the Prolog we have used the variable to tell the AttrInsert to create a new String attribute called ‘Status’ in the Employees dimensions after the existing ‘Name’ attribute.
Real World Usage
Interestingly we had immediately prior to this function in our TI used AttrDelete to delete the attribute. This effectively clears out all the values in the attribute before then on the Metadata or Data tab we re-populate it with current information.
Also, we sometimes want to check if an Attrubute exists prior to doing an insert. Please see this post about how to effecively do an AttributeExists function (even though it does not exist in TM1!).
Note that if you are going to create an attribute and then populate it in a single TI, you must create the attribute on the Prolog tab and then populate it on either the Metadata or Data tab.
This function can only be used in Turbo Integrator processes.