Attribute Definition Problem
I just had an instance where I was adding new elements to a dimension in TM1 and then wanted to define an attribute for those new elements. Easy, yeah? Just test if an element is there with a Dimix, then use a DimensionElementInsert and then an AttrPutS or AttrPutN to define the attribute. Well, not quite.
I had it all on the metadata tab, but even though the new element was being added, the attribute was not being defined. In other words, the AttrPutS or AttrPutN was not working. A bit of research later and I found that the additions to the dimension are only processed at the end of the Metadata process, effectively in batch. At this point the script has gone past defining the attribute, so it gets left as blank.
The solution to this problem was to split the code into both the Metadata and Data tabs. Use the Metadata tab for adding the new elements (and sorting them with DimensionSortOrder if required). Then on the Data tab use an ATTRS to check for an empty attribute and then define it as required.
Note that doing this will force the source data to be read twice – once each for Metadata and Data.