Page 1 of 1

DimElCompAdd Not adding anything :(

Posted: Fri Mar 08, 2013 5:56 pm
by Carl Lonsdale
Hey all,
Starting Learning TM1 about a month ago, so at the risk of this being something incredibly asinine, here is the issue I have run into:

I am writing a process to either replace or amend a Dimension (user choice) using the input from a CSV. The CSV has 5 columns but here we are only dealing with 3. The first which is the element name. 3rd - EntityID, 4-EntityParentID. However the Dim hierarchy is supposed to be built on the 3rd and 4th Column IDs. So I have added these as Attributes. With each element's EntityID set to an Alias.
And Each element's EntityParentID set to a string Attribute.
The 1st Column the element's name, though all numbers I have also set to string for the purposes of making it easier to manage. (Less NTS calls).

On the Surface everything runs and checks out fine. ASCII outs are telling me exactly what I would hope to see. However once I get to the last step and the process completes successfully. I find I am left with no hierarchies at all. Just a single consolidated Orphans element and the relevant Level - 0's from the CSV and no parent/child relationships.

CSV Preview:
BUSINESS_UNIT DESCRIPTION EntityID ParentEntityID
527463 PB OTHER 1656392 1879149
418830 ASIA SOLUTION 1349775 1656392
425008 PB SPAIN - IC(JPMCB) 1355878 1656392
425009 PB SPAIN - IC(JPM SV) 1355879 1656392
423112 PB ADMIN - LATAM BRAZIL 1353982 1656392

PROLOG

Code: Select all

####################PROLOG #####################
################################################
	
#Dimension Declaration
sDimName='BU';

#If Wipe Dim was Yes Vaporizes Dimension
IF (pDeleteAll@='YES'); DimensionDeleteAllElements(sDimName); ENDIF;

#Deletes all Elements Higher than Level 0
#If User Answered Yes to pReplace prompt
IF(pReplace@='Yes');
	iIndex=DIMSIZ (sDimName);
	WHILE(iIndex>=1);
		sElement=DIMNM ( sDimName, iIndex );
		IF ( DTYPE ( sDimName, sElement )@='C' %  ELLEV ( sDimName, sElement )<>0);
			DimensionElementDelete(sDimName, sElement);
		ENDIF;
		iIndex=iIndex-1;
	END;
ENDIF;

#If Orpahns doesn't exist create it.
IF( DIMIX ( sDimName, 'Orphans') =0);
	DimensionElementInsert ( sDimName, '', 'Orphans','C');
ENDIF;

#Create our 2 Attributes
AttrInsert(sDimName, '', 'EntityID', 'A');
AttrInsert(sDimName, '', 'ParentEntityID', 'S');
METADATA

Code: Select all

##################META-DATA#######################

sCurrentElem=vBUSINESS_UNIT;
IF( DIMIX( sDimName, sCurrentElem) = 0 );
 	# the new element is unique, let's add it
 	DimensionElementInsert( sDimName, '', sCurrentElem, 'N');
	#Assign it Attributes 'EntityID (Alias)' & 'ParentEntityID(String)' 
	AttrPutS ( vEntityID, sDimName, sCurrentElem, 'EntityID');
	AttrPutS (  vParentEntityID, sDimName, sCurrentElem, 'ParentEntityID');
Else;
	#It Exists, findout where: principal or Alias:
 	sPrincipalNm = DimensionElementPrincipalName( sDimName, vEntityID );
	IF( sCurrentElem @= sPrincipalNm );
 	  	# the new element matches the name of an already exusting element so we can't add it
 	  	ItemReject( sCurrentElem | ' 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( sCurrentElem | ' matches an alias value of element ' | sPrincipalNm);
	EndIF;
EndIF;
DATA

Code: Select all

################ DATA ########################
sCurrentElem=vBUSINESS_UNIT;
#Set sTarPar to the Element name of the Current Element's ParentID
sTarPar=DimensionElementPrincipalName( sDimName, vParentEntityID );
#If the current Elem's PARENT exists in the Dimension:
IF( DIMIX( sDimName, sTarPar ) <>0 );
	#Add the current Elem to the Target Parent
	DimensionElementInsert( sDimName, '', sCurrentElem, 'N');
	DimensionElementComponentAdd ( sDimName, sTarPar, sCurrentElem, 1);
ELSE;
	#Add the Element to Orphans
	DimensionElementInsert( sDimName, '', sCurrentElem, 'N');
	DimensionElementComponentAdd ( sDimName, 'Orphans', sCurrentElem, 1);
ENDIF;
EPILOGE

Code: Select all

DimensionSortOrder(sDimName, 'ByName', 'Descending',
'ByHierarchy' , 'Descending');
Anyhow help/input/critiques all welcome.
-Thanks in advance! :)

Re: DimElCompAdd Not adding anything :(

Posted: Fri Mar 08, 2013 6:28 pm
by qml
At the risk of sounding obvious: Metadata tab is for metadata changes, Data tab is for data changes.

Your problem is that you are trying to use data functions like AttrPutS on the Metadata tab and metadata functions like DimensionElementInsert or DimensionElementComponentAdd on the Data tab. Do it the other way round.

Re: DimElCompAdd Not adding anything :(

Posted: Fri Mar 08, 2013 6:33 pm
by Carl Lonsdale
qml wrote:At the risk of sounding obvious: Metadata tab is for metadata changes, Data tab is for data changes.

Your problem is that you are trying to use data functions like AttrPutS on the Metadata tab and metadata functions like DimensionElementInsert or DimensionElementComponentAdd on the Data tab. Do it the other way round.
Yup....Now that you say it. It does seem obvious. Ha.
Literally just switched them and presto.
Your a boss. Thanks for Help! :D