Manual setting new element name

Post Reply
User avatar
ioscat
Regular Participant
Posts: 209
Joined: Tue Jul 10, 2012 8:26 am
OLAP Product: Contributor
Version: 9.5.2 10.1.1 10.2
Excel Version: 07+10+13
Contact:

Manual setting new element name

Post by ioscat »

Hello tm1forum.
I want to create new elements with names 001123, 001124.. etc. How can I do this?

Code: Select all

#Metadata:

Count = DimSiz (%MyDimension)+1;
ElementName = NumberToString(Count);
Length1 = Long(%MyDimension, Dimnm(%MyDimension, 1));
Length2 = Long(ElementName);
While (Length1-Length2 > 0);
    ElementName = '0' | ElementName;
    Lenth1 = Length1-1;
End;
DimensionElementInsert(%MyDimension, , ElementName, 's');
What's wrong?
User avatar
qml
MVP
Posts: 1098
Joined: Mon Feb 01, 2010 1:01 pm
OLAP Product: TM1 / Planning Analytics
Version: 2.0.9 and all previous
Excel Version: 2007 - 2016
Location: London, UK, Europe

Re: Manual setting new element name

Post by qml »

I can see at least three errors in the above code:

1) Long() takes only one argument, not two.
2) You have a typo in the name of your variable Lenth1, so you're probably causing an infinite loop there.
3) You cannot start variable names wih the % character.

The logic seems qute convoluted, I have no idea how this is meant to achieve the simple goal that is generating new element names. You need half the number of code lines for that.

Also, you are not even telling us what the datasource for this TI process is and why you put the code in the Metadata tab. As it stands, it has no real chance of working.
Kamil Arendt
User avatar
ioscat
Regular Participant
Posts: 209
Joined: Tue Jul 10, 2012 8:26 am
OLAP Product: Contributor
Version: 9.5.2 10.1.1 10.2
Excel Version: 07+10+13
Contact:

Re: Manual setting new element name

Post by ioscat »

qml, thanks for comments. I'll try to make complete answer.

I'm trying to get update to my cube with new elements named '0001123', '0001124'... etc. Datasource is .CSV file.
I'm using metadata tab because TI uses it to add new elements to the dimension.

Code: Select all

#****Begin: Generated Statements***
#****End: Generated Statements****
#Metadata

user.MyDimension = 'protfcp_LongList';
user.LastElement = DimSiz (user.MyDimension);
user.DimensionElementNameLength = Long(Dimnm(user.MyDimension, 1));
user.ElementName = NumberToString(user.LastElement+1);
user.ElementNameLength = Long(user.ElementName);
While ( user.ElementNameLength - user.DimensionElementNameLength < 0);
    user.ElementName = '0' | user.ElementName;
    user.ElementNameLength = user.ElementNameLength + 1;
End;
DimensionElementInsert(user.MyDimension , , user.ElementName , 's');
tomok
MVP
Posts: 2836
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: Manual setting new element name

Post by tomok »

The code inside your WHILE loop is never going to execute because the initial state is always going to be false. user.ElementNameLength - user.ElementNameLength is always going to equal zero.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
User avatar
qml
MVP
Posts: 1098
Joined: Mon Feb 01, 2010 1:01 pm
OLAP Product: TM1 / Planning Analytics
Version: 2.0.9 and all previous
Excel Version: 2007 - 2016
Location: London, UK, Europe

Re: Manual setting new element name

Post by qml »

I just love it when users post their problems along with some code that turns out not to be the actual code they are using. What a waste of time.
Kamil Arendt
User avatar
ioscat
Regular Participant
Posts: 209
Joined: Tue Jul 10, 2012 8:26 am
OLAP Product: Contributor
Version: 9.5.2 10.1.1 10.2
Excel Version: 07+10+13
Contact:

Re: Manual setting new element name

Post by ioscat »

tomok wrote:The code inside your WHILE loop is never going to execute because the initial state is always going to be false. user.ElementNameLength - user.ElementNameLength is always going to equal zero.
Not that, user.ENL - user.DimensionENL
qml wrote:I just love it when users post their problems along with some code that turns out not to be the actual code they are using. What a waste of time.
I'm just modifying it in the fly. Anyway, I really have to change it: it consist of cyrillic letters. Please, be kind/tolerate.

Code: Select all

#Prolog:
DimensionDeleteAllElements('protfcp_LongList');

#Meta:
user.MyDimension = 'protfcp_LongList';
user.LastElement = DimSiz (user.MyDimension);

If ( user.LastElement <> 0);

    user.DimensionElementNameLength = Long(Dimnm(user.MyDimension, 1));
#    user.DimensionElementNameLength = 6;
    user.ElementName = NumberToString(user.LastElement+1);
    user.ElementNameLength = Long(user.ElementName);

    While ( user.ElementNameLength - user.DimensionElementNameLength < 0);
        user.ElementName = '0' | user.ElementName;
        user.ElementNameLength = user.ElementNameLength + 1;
    End;

Elseif (user.LastElement = 0);

     user.ElementName = '000001';

Endif;

DimensionElementInsert(user.MyDimension , '' , user.ElementName , 's');

#Data:
CellPutS(variable1, 'protfcp_EmittersList', user.ElementName, 'MeasuresDimensionElement1');
CellPutS(variable2, 'protfcp_EmittersList', user.ElementName, 'MeasuresDimensionElement2');

AttrPutS(variable2, 'protfcp_Longlist', user.ElementName, 'AliasName');
Now it works without errors, but it fills only last string of my spreadsheet. It seems to cycle first on Meta code and taking maxium (last) user.ElementName start cycle on Data code.

All variables set to "OTHER" in "Variables" tab.
Last edited by ioscat on Mon Aug 06, 2012 4:30 pm, edited 1 time in total.
tomok
MVP
Posts: 2836
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: Manual setting new element name

Post by tomok »

user.DimensionElementNameLength = Long(Dimnm(user.MyDimension, 1));

This is always going to evaluate to 0.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
User avatar
ioscat
Regular Participant
Posts: 209
Joined: Tue Jul 10, 2012 8:26 am
OLAP Product: Contributor
Version: 9.5.2 10.1.1 10.2
Excel Version: 07+10+13
Contact:

Re: Manual setting new element name

Post by ioscat »

tomok wrote:user.DimensionElementNameLength = Long(Dimnm(user.MyDimension, 1));

This is always going to evaluate to 0.

Code: Select all

user.LastElement = DimSiz (user.MyDimension);
for example dimension size equals 12345, so user.LE = 12345

Code: Select all

user.DimensionElementNameLength = Long(Dimnm(user.MyDimension, 1));
first element of dim is '000001', so user.DENL = 6

Code: Select all

user.ElementName = NumberToString(user.LastElement+1);
user.EN = 12346

Code: Select all

user.ElementNameLength = Long(user.ElementName);
user.ENL = 5

isn't it? Maybe I'm missing smth?
User avatar
ioscat
Regular Participant
Posts: 209
Joined: Tue Jul 10, 2012 8:26 am
OLAP Product: Contributor
Version: 9.5.2 10.1.1 10.2
Excel Version: 07+10+13
Contact:

Re: Manual setting new element name

Post by ioscat »

Still can't get why:
tomok wrote:user.DimensionElementNameLength = Long(Dimnm(user.MyDimension, 1));

This is always going to evaluate to 0.
It seems I solved the problem and it was a little win of a little challenge.

I added user.Count variable in Meta tab because TI was cycling for each tab in series and when Data tab code started to run user.ElementName variable was set to last element. The final code is (yes, cyrillic was retyped):

Code: Select all

#Prolog:
DimensionDeleteAllElements('protfcp_LongList');

#Meta:
user.MyDimension = 'protfcp_LongList';
user.LastElement = DimSiz (user.MyDimension);

If ( user.LastElement <> 0);

    user.DimensionElementNameLength = Long(Dimnm(user.MyDimension, 1));
#    user.DimensionElementNameLength = 6;
    user.ElementName = NumberToString(user.LastElement+1);
    user.ElementNameLength = Long(user.ElementName);

    While ( user.ElementNameLength - user.DimensionElementNameLength < 0);
        user.ElementName = '0' | user.ElementName;
        user.ElementNameLength = user.ElementNameLength + 1;
    End;

Elseif (user.LastElement = 0);

    user.ElementName = '000001';

Endif;

DimensionElementInsert(user.MyDimension , '' , user.ElementName , 's');

user.Count = 1;

#Data:

user.ElementName = Dimnm(user.MyDimension, user.Count);


CellPutS(variable1,'protfcp_TransmitObjectsAttributes',user.ElementName,'MeasuresDimensionEl1');
#...here were many strings of similar code
CellPutS(variable2,'protfcp_TransmitObjectsAttributes',user.ElementName,'MeasuresDimensionEl2');

AttrPutS(variable1, 'protfcp_Longlist', user.ElementName, 'AliasName');

user.Count = user.Count + 1;
Maybe the code is ugly (I'm not coder/programmer) and works too long (yes, really too long), but now I can afford myself to finish work day.
Last edited by ioscat on Tue Aug 07, 2012 6:36 am, edited 1 time in total.
User avatar
mattgoff
MVP
Posts: 518
Joined: Fri May 16, 2008 1:37 pm
OLAP Product: TM1
Version: 10.2.2.6
Excel Version: O365
Location: Florida, USA

Re: Manual setting new element name

Post by mattgoff »

ioscat wrote:I'm just modifying it in the fly. Anyway, I really have to change it: it consist of cyrillic letters. Please, be kind/tolerate.
That's the first ever good excuse I've seen for a retype. Doesn't excuse the typo, but it's understandable. Glad you got it fixed.

Matt
Please read and follow the Request for Assistance Guidelines. It helps us answer your question and saves everyone a lot of time.
User avatar
ioscat
Regular Participant
Posts: 209
Joined: Tue Jul 10, 2012 8:26 am
OLAP Product: Contributor
Version: 9.5.2 10.1.1 10.2
Excel Version: 07+10+13
Contact:

Re: Manual setting new element name

Post by ioscat »

Good morning.
mattgoff, could you explain this:
tomok wrote:user.DimensionElementNameLength = Long(Dimnm(user.MyDimension, 1));

This is always going to evaluate to 0.
Is it true? Or tomok is mistaken? New day started and I still has no idea. I't a kind of stress %-).
rozef
Posts: 74
Joined: Thu Jun 17, 2010 10:35 am
OLAP Product: TM1
Version: 9.4 9.5.1
Excel Version: 2003 - 2007

Re: Manual setting new element name

Post by rozef »

Hi ioscat,

there is an easier trick if you want create elements 001123, 001124, etc.

start with a number of one figure larger, 1001123 that you increase for insert other element.
For each make a substring of the numeric value after having converted it in string:

Code: Select all

MyElement = SUBST( NumberToString( MyNumericElement ) , 2 , 6 );
(easier then loop on size)

Cheers,
User avatar
ioscat
Regular Participant
Posts: 209
Joined: Tue Jul 10, 2012 8:26 am
OLAP Product: Contributor
Version: 9.5.2 10.1.1 10.2
Excel Version: 07+10+13
Contact:

Re: Manual setting new element name

Post by ioscat »

Yep, your way is a cheat or secret door to the next level instead of jumping under deep and beating all enemies and a level boss %) thanks for the idea!
User avatar
ioscat
Regular Participant
Posts: 209
Joined: Tue Jul 10, 2012 8:26 am
OLAP Product: Contributor
Version: 9.5.2 10.1.1 10.2
Excel Version: 07+10+13
Contact:

Re: Manual setting new element name

Post by ioscat »

Found one more way:
NumberToStringEx that allows to make custom format of string number
Post Reply