Page 1 of 1

Insert Element in Dimension, Set Attribute

Posted: Mon Jan 09, 2012 10:34 am
by maps
Hi everyone,

I'm struggeling with updateing a dimension. I just want to load the elements out of a textfile into a dimension and set a attribute 'Status'. But always the following error occurs:

Code: Select all

...Data Source line (1) Error: MetaData procedure line (8): Element "10010." not found in dimension "dim_Empl".
         ...
Line 8 refers to the AttrPutS statement.

MetaData:

Code: Select all

IF( DIMIX( cDimName, vPersID) = 0);
  DimensionElementInsert( cDimName, '', vPersID, 'N');
  IF( DIMIX( cDimName, vPersID) <> 0);
    AttrPutS( 'EXISTS', cDimName, vPersID, cAttrStatus);
  ENDIF;
ELSE;

  AttrPutS( 'ACTIVE', cDimName, vPersID, cAttrStatus);
ENDIF;
Because I always got the error I inserted the second DIMIX statement to ensure that the element of the dimension really exists. What am I doing wrong? Any ideas?

Re: Insert Element in Dimension, Set Attribute

Posted: Mon Jan 09, 2012 10:53 am
by Edward Stuart
Edit: After engaging my brain I realised I was wrong!

Although checking through the help files for AttrInsert/ AttrDelete it doesn't mention where it needs to be placed in the TI process.

Re: Insert Element in Dimension, Set Attribute

Posted: Mon Jan 09, 2012 11:02 am
by Michel Zijlema
Hi maps,

Please note that the dimension is only saved after the Metadata run has finished - so all elements that have been added will be available after the MetaData script has completed, this is at the start of the Data run.
Setting attribute values is in fact loading data in the corresponding }ElementAttributes cube. In order to be able to load data, the regarding cell to load needs to be available - this will be after the changes to the required dimensions have been saved. So loading the attribute values will be something you do in the Data tab script, not in the MetaData tab script.

Michel

Re: Insert Element in Dimension, Set Attribute

Posted: Mon Jan 09, 2012 11:07 am
by maps
But how can I set the attribute with the status? When the metadata tab has finished the element is already in the dimension and it doesn't make any sense to use the dimix statement again. How can I flag that the element didn't exist before using a flag? any advice?

Re: Insert Element in Dimension, Set Attribute

Posted: Mon Jan 09, 2012 11:14 am
by Michel Zijlema
maps wrote:But how can I set the attribute with the status? When the metadata tab has finished the element is already in the dimension and it doesn't make any sense to use the dimix statement again. How can I flag that the element didn't exist before using a flag? any advice?
You could create a temporary dimension and list new elements in this dimension. On the data tab you could set the status based on the availablity of the element in this temporary dimension.

Michel

Re: Insert Element in Dimension, Set Attribute

Posted: Mon Jan 09, 2012 11:16 am
by Michel Zijlema
Another option could be to have an alternative hierarchy called 'New elements' in your dimension and add the new elements to this alternative hierarchy. This way you don't need an attribute to flag new elements.

Michel

Re: Insert Element in Dimension, Set Attribute

Posted: Mon Jan 09, 2012 11:39 am
by Duncan P
This is very similar to the problem discussed in this thread http://www.tm1forum.com/viewtopic.php?f=3&t=6669

Re: Insert Element in Dimension, Set Attribute

Posted: Mon Jan 09, 2012 12:07 pm
by David Usherwood
I've used another technique in the past:

a Have a working cube dimensioned by your dimension;
b Fill it with 1s before doing the dimension load;
c Then the elements showing 0 are the new ones.

Re: Insert Element in Dimension, Set Attribute

Posted: Mon Jan 09, 2012 12:37 pm
by lotsaram
David Usherwood wrote:I've used another technique in the past:

a Have a working cube dimensioned by your dimension;
b Fill it with 1s before doing the dimension load;
c Then the elements showing 0 are the new ones.
This forum should have a hat tip smiley. I'll have to add that one to the play list.

Re: Insert Element in Dimension, Set Attribute

Posted: Thu Jan 12, 2012 12:15 pm
by maps
I had the problem that I have to distinguish between 3 different kind of elements of the dimension.
When I'm imoprting element to the dimension the element can be an "new one" (does not exist yet), "already existing". All other elements of the dimension (elements which are not in the import file are "old ones".

I implemented it now in the following way. I created a new tmp dimension "}blabla" added all the new elements in the metadatatab. The already existing one I could already flag in the metadata tab.

The new ones I flagged in the data tab. For this I iterated over all the elements of my new Dimension and inserted the value of the attribute. To make shure that this procedure is only executed once i used a flag I created in the prolog.

Code: Select all

prolog 
cFlag = 0;

datatab
if(cFlag = 0); 
  cFlag = 1;
    While...
  ENd;
So I was able to flag "new" and "already existing" element. Elements which are not used anymore do not have a entry for the attribute...