Page 1 of 1
Dimension Element Delete NOT Working
Posted: Mon Jan 13, 2014 12:28 pm
by roy2087
Hi,
I have Dimension 2h_District.
2h_District has a TEXT Attribute , Company.
Now, I want to delete all the elements in 2h_District where Company in NULL.
Eg.
District Company
N201 IN10
N202 (Blank)
I wrote a Code in TI Metadata.
If
(
ATTRS('2h_District',vDistrict,'Company') @=' '
);
DimensionElementDelete('2h_District',vDistrict);
itemskip;
ENDIF;
Result should be:-
N202 should be deleted from 2h_District
But, this code is NOT working.
Can anyone help me please?
Regards,
Roy.
Re: Dimension Element Delete NOT Working
Posted: Mon Jan 13, 2014 12:43 pm
by Tm1andTm1
Hi Roy,
It seems you have used ATTRS widely in the project.
ATTRS is good function of TM1, but still very dangerous if used without caution.
Re: Dimension Element Delete NOT Working
Posted: Mon Jan 13, 2014 1:01 pm
by declanr
Roy,
Just stick an extra line in your TI process to do an asciioutput of whatever the AttrS does return and then you will see why it is not matching your conditions.
Tm1andTm1 wrote:Hi Roy,
It seems you have used ATTRS widely in the project.
ATTRS is good function of TM1, but still very dangerous if used without caution.
TM1andTM1,
I would say that this expands to every function within any code language... if you don't use functions correctly there will be issues.
This seems a normal way to use it though.
Re: Dimension Element Delete NOT Working
Posted: Mon Jan 13, 2014 1:24 pm
by lotsaram
Tm1andTm1 wrote:ATTRS is good function of TM1, but still very dangerous if used without caution.
What exactly do you mean by that? Please explain how ATTRS can be "dangerous".
Re: Dimension Element Delete NOT Working
Posted: Mon Jan 13, 2014 1:50 pm
by Wim Gielis
lotsaram wrote:Tm1andTm1 wrote:ATTRS is good function of TM1, but still very dangerous if used without caution.
What exactly do you mean by that? Please explain how ATTRS can be "dangerous".
Attribute values could be empty for an alias (but that would not be an issue for text attributes, in that case it's empty and you (should) know it).
Re: Dimension Element Delete NOT Working
Posted: Thu Jan 16, 2014 10:31 am
by Tm1andTm1
lotsaram wrote:Tm1andTm1 wrote:ATTRS is good function of TM1, but still very dangerous if used without caution.
What exactly do you mean by that? Please explain how ATTRS can be "dangerous".
Lotsaram
It is difficult to put in words,
Well..... it would be your experience which can give you the answer of this question.....
Re: Dimension Element Delete NOT Working
Posted: Thu Jan 16, 2014 11:11 am
by Steve Vincent
roy2087 wrote:
If (ATTRS('2h_District',vDistrict,'Company') @=' ' );
DimensionElementDelete('2h_District',vDistrict);
itemskip;
ENDIF;
Think you are missing an ELSE statement, try;
Code: Select all
If (ATTRS('2h_District',vDistrict,'Company') @=' ' );
DimensionElementDelete('2h_District',vDistrict);
ELSE;
itemskip;
ENDIF;
Re: Dimension Element Delete NOT Working
Posted: Thu Jan 16, 2014 12:06 pm
by MSidat
Maybe others can correct me If I am wrong but I know TM1 is not Space sensitive when it comes to element names etc however it can be for Data.
As such you might want to search for '' instead of ' ' in ATTRS or always search for '' and wrap your attrs with a TRIM function.
Hope this helps.
Re: Dimension Element Delete NOT Working
Posted: Thu Jan 16, 2014 12:35 pm
by declanr
Steve Vincent wrote:
Think you are missing an ELSE statement, try;
Code: Select all
If (ATTRS('2h_District',vDistrict,'Company') @=' ' );
DimensionElementDelete('2h_District',vDistrict);
ELSE;
itemskip;
ENDIF;
Not sure without seeing what else is in the code but I had assumed it was meant to be along the lines of:
If the District doesn't have a company attribute - Delete the Element
AND skip the rest of the code on that tab...
otherwise - continue with the rest of the code for the Elements that still exist.
Re: Dimension Element Delete NOT Working
Posted: Thu Jan 16, 2014 1:07 pm
by lotsaram
Tm1andTm1 wrote:ATTRS is good function of TM1, but still very dangerous if used without caution.
....
It is difficult to put in words,
Well..... it would be your experience which can give you the answer of this question.....
No really in all seriousness. In
your (I'm sure enormous) experience please do elucidate on how ATTRS can be a dangerous function and how do you suggest caution in its use versus wild abandon?
Re: Dimension Element Delete NOT Working
Posted: Thu Jan 16, 2014 8:47 pm
by jim wood
Tm1andTm1 wrote:ATTRS is good function of TM1, but still very dangerous if used without caution.
Erm, I'm a little stumped here. Surely CellPutS is more dangerous as not only can you update data cells you can also achieve the same as a ATTRS when sending data to control cubes?
Re: Dimension Element Delete NOT Working
Posted: Thu Jan 16, 2014 11:12 pm
by rmackenzie
roy2087 wrote:I wrote a Code in TI Metadata.
If
(
ATTRS('2h_District',vDistrict,'Company') @=' '
);
DimensionElementDelete('2h_District',vDistrict);
itemskip;
ENDIF;
Although it is not the case with all TI functions, it is definitely the case with ATTRS that it is not a good coding practice in TI to put the function directly within the condition of an IF statement. Try these two examples in a test process and you will see that in the case of the first example, no error is thrown and, in fact,
the 'false' clause is executed. IMHO this creates unacceptable risk:
Code: Select all
nResult = 1;
# no error thrown on next line even though dimension does not exist - condition just evaluates to FALSE
IF ( ATTRS ( 'Not_Exists', 'Me_Neither', 'Foo' ) @= 'Bar' );
nResult = 2;
ELSE;
nResult = 3;
ENDIF;
ItemReject ( 'Answer is: ' | NumberToString ( nResult ) );
The correct coding technique is to set a variable before the IF statement. In this case, TI will correctly throw an error:
Code: Select all
nResult = 1;
# error occurs on next line because no such dimension exists
sAttritbuteValue = ATTRS ( 'Not_Exists', 'Me_Neither', 'Foo' );
# this logic is never evaluated as process has aborted
IF ( sAttritbuteValue @= 'Bar' );
nResult = 2;
ELSE;
nResult = 3;
ENDIF;
ItemReject ( 'Answer is: ' | NumberToString ( nResult ) );
Using this technique in conjunction with the earlier advice to use AsciiOutput/ TextOutput commands on the problem attribute should help you debug your code.
Re: Dimension Element Delete NOT Working
Posted: Wed Jan 22, 2014 8:46 am
by roy2087
Hi,
I have made some changes in the Data Source section.
Earlier, I was using "Cube View" as a Data Source,
but now I am using "Dimension Sub" as a Data Source.
In the Dimension(2h_District), I have made a subset which has only Leaf Level elements.
Then , I am using this following code in the Metadata Section..
**************************************************************
If
(
ATTRS('2h_District',vDistrict,'Company') @=' '
);
DimensionElementDelete('2h_District',vDistrict);
itemskip;
ENDIF;
*************************************************************
Phew..! It worked.
Did'nt know changing the Data Source would make such as a difference.
Thanks everyone!
Roy....
Re: Dimension Element Delete NOT Working
Posted: Wed Jan 22, 2014 8:51 am
by Tm1andTm1
Hi roy2087,
Have you got the solution you require......? If not, please let me know
Re: Dimension Element Delete NOT Working
Posted: Wed Jan 22, 2014 10:07 am
by roy2087
Yes, I have got the solution.