Page 1 of 1
Manual setting new element name
Posted: Mon Aug 06, 2012 2:39 pm
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?
Re: Manual setting new element name
Posted: Mon Aug 06, 2012 2:52 pm
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.
Re: Manual setting new element name
Posted: Mon Aug 06, 2012 3:10 pm
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');
Re: Manual setting new element name
Posted: Mon Aug 06, 2012 3:32 pm
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.
Re: Manual setting new element name
Posted: Mon Aug 06, 2012 3:35 pm
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.
Re: Manual setting new element name
Posted: Mon Aug 06, 2012 4:10 pm
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.
Re: Manual setting new element name
Posted: Mon Aug 06, 2012 4:30 pm
by tomok
user.DimensionElementNameLength = Long(Dimnm(user.MyDimension, 1));
This is always going to evaluate to 0.
Re: Manual setting new element name
Posted: Mon Aug 06, 2012 4:36 pm
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?
Re: Manual setting new element name
Posted: Mon Aug 06, 2012 5:29 pm
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.
Re: Manual setting new element name
Posted: Tue Aug 07, 2012 1:51 am
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
Re: Manual setting new element name
Posted: Tue Aug 07, 2012 6:30 am
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 %-).
Re: Manual setting new element name
Posted: Tue Aug 07, 2012 8:27 am
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,
Re: Manual setting new element name
Posted: Tue Aug 07, 2012 8:53 am
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!
Re: Manual setting new element name
Posted: Thu Aug 09, 2012 8:34 am
by ioscat
Found one more way:
NumberToStringEx that allows to make custom format of string number