Page 1 of 1
Determining if an alias exists in a dimension
Posted: Wed Oct 13, 2010 1:35 pm
by dan.kelleher
Hi,
In a TI process I want to add an element, say variable X, to a dimension if the element name doesn't exist (using Dimix, straightforward) and if no element has variable X as an alias within the same dimension.
I know that trying the addition will result in an error if an alias with the same name exists, and I also know I can use a while loop to test if each element's alias is the same, but is there an easier way using the inbuilt rule or Ti functions? From what I can see there is not, and I want to avoid error messages, however harmless, appearing in the message log unnecessarly.
Thanks,
Dan
Re: Determining if an alias exists in a dimension
Posted: Wed Oct 13, 2010 1:48 pm
by jstrygner
Dan,
If you test via DimIx, if an element exists in a Dimension the function checks both basic names of elements and alias names.
So if there is an element with basic name or alias equal to 'X', DimIx will return index of such an element.
You would need iteration if you need to check for a text attribute that does need to be unique, but that is not your case from what I understand.
HTH
Re: Determining if an alias exists in a dimension
Posted: Wed Oct 13, 2010 1:51 pm
by tomok
The ElementName argument of DIMIX, i.e., DIMIX(DimName,ElementName) can either be an actual element name OR an alias so if you DIMIX with the element you want to add it will return a value of greater than 1 if either that actual element already exists or it is an alias of another element that already exists.
Re: Determining if an alias exists in a dimension
Posted: Wed Oct 13, 2010 1:52 pm
by dan.kelleher
Thanks!
Re: Determining if an alias exists in a dimension
Posted: Wed Oct 13, 2010 10:04 pm
by lotsaram
dan.kelleher wrote:Hi,
In a TI process I want to add an element, say variable X, to a dimension if the element name doesn't exist (using Dimix, straightforward) and if no element has variable X as an alias within the same dimension.
I know that trying the addition will result in an error if an alias with the same name exists, and I also know I can use a while loop to test if each element's alias is the same, but is there an easier way using the inbuilt rule or Ti functions? From what I can see there is not, and I want to avoid error messages, however harmless, appearing in the message log unnecessarly.
Thanks,
Dan
I think I get what you're trying to do an yes there is an easier way than looping through all attributes for the member and checking against the values for DTYPE 'AA'. Here is some (untested) code which check against both DIMIX and DimensionElementPrincipalName
Code: Select all
## This code on META DATA ##
IF( DIMIX(cDim, sNewEle) = 0 );
# the new element is unique, let's add it
DimensionElementInsert(cDim, '', sNewEle, 'N');
Else;
sPrincipalNm = DimensionElementPrincipalName(cDim, sNewEle);
IF( sNewEle @= sPrincipalNm );
# the new element matches the name of an already exusting element so we can't add it
ItemReject(sNewEle | ' matches a pre-existing element principal name');
Else;
# the new element matches the alias of an already exusting element so we can't add it
ItemReject(sNewEle | ' matches an alias value of element ' | sPrincipalNm);
EndIF;
EndIF;