Original Message:
Sent: Sun July 09, 2023 07:58 PM
From: John O'Leary
Subject: TI Process to add new element to dimension with automated Element Name template
This is some recent code I have written, which is based on something someone else had already written so I don't claim originality.
# Constants
#--dimension to update
cs_DimName = 'Capital Planning Asset';
cs_AllPlannedAssets = 'All Planned Assets';
if(DimensionExists(cs_DimName)=0);
DimensionCreate ( cs_DimName );
Endif;
HierarchyElementInsert(cs_DimName, cs_DimName, '', cs_AllPlannedAssets, 'C');
sSub_Src_PA00 = 'Src.' | s_UniqueName |'_PA00';
#-- counters
n_ErrorCount = 0;
#-- generate a code
#-- create a subset of all Planned Assets and count the size.
#-- the code seq number is subset size + 1
#-- Create a Subset
if(HierarchySubsetExists(cs_DimName, cs_DimName, sSub_Src_PA00)=0);
HierarchySubsetCreate(cs_DimName, cs_DimName, sSub_Src_PA00, 1);
endif;
#--capital members subset
cs_MDX = '{TM1FILTERBYPATTERN( {TM1SUBSETALL(['|cs_DimName|'])}, "PA00*")}';
#-- Set an MDX
HierarchySubsetMDXSet(cs_DimName, cs_DimName, sSub_Src_PA00,cs_MDX);
HierarchySubsetMDXSet(cs_DimName, cs_DimName, sSub_Src_PA00,'');
#compare new number to cn_MaxNumber and make cn_MaxNumber the higher
#when finished then change n_PA_Seq_Number_PA00 =cn_MaxNumber + 1;
n_SubsetSize_PA00 = HierarchySubsetGetSize(cs_DimName, cs_DimName, sSub_Src_PA00);
nPlannedAsset_Subset_Index = 1;
cn_MaxNumber = 0;
cs_PA_Number_As_Str = '';
cn_PA_Number_As_Numbr = 0;
while (nPlannedAsset_Subset_Index <= n_SubsetSize_PA00);
sPASubsetCurrentElementName = HierarchySubsetGetElementName(cs_DimName,cs_DimName ,sSub_Src_PA00, nPlannedAsset_Subset_Index);
cs_PA_Number_As_Str = subst(sPASubsetCurrentElementName, 5 , long(sPASubsetCurrentElementName) -4 );
cn_PA_Number_As_Numbr = numbr (cs_PA_Number_As_Str);
if (cn_PA_Number_As_Numbr > cn_MaxNumber);
cn_MaxNumber = cn_PA_Number_As_Numbr;
Endif;
nPlannedAsset_Subset_Index = nPlannedAsset_Subset_Index + 1;
end;
#-- working out a seq number of Planned Asset
n_PA_Seq_Number_PA00 = cn_MaxNumber + 1;
s_PA_Seq_Number_PA00 = NumberToString(n_PA_Seq_Number_PA00);
#-- Planned Capital calculated Seq number
s_PA_Code_PA00 = 'PA00' | FILL('0', 7 - LONG(s_PA_Seq_Number_PA00))|s_PA_Seq_Number_PA00;
#-- add a new Planned Asset member
HierarchyElementInsertDirect( cs_DimName,cs_DimName, '' ,s_PA_Code_PA00, 'N');
#-- assign to Parent
HierarchyElementComponentAdd(cs_DimName, cs_DimName, cs_AllPlannedAssets ,s_PA_Code_PA00, 1);
------------------------------
John O'Leary
Original Message:
Sent: Fri July 07, 2023 09:50 PM
From: calvin winardi
Subject: TI Process to add new element to dimension with automated Element Name template
Hi thanks for the advice i already did that but the main problem is when it comes to the 10, it will be "PDT0010" bot a "PDT010" and so on... it also will be 'PDT00100' and etc
------------------------------
calvin winardi
Original Message:
Sent: Fri July 07, 2023 08:14 AM
From: John O'Leary
Subject: TI Process to add new element to dimension with automated Element Name template
Yes it is possible in several ways. The simplest way is to create a MDX based temporary subset sorted in reverse, reference the first element in the subset, perform a substring of the last x characters, convert to a number, add 1, convert back to string and concatenate with the relevant prefix then insert the element.
------------------------------
John O'Leary
Original Message:
Sent: Fri July 07, 2023 04:10 AM
From: calvin winardi
Subject: TI Process to add new element to dimension with automated Element Name template
Hi guys, im having some question, is it possible for me to can make a TI Process where when user trigger that process, it will be automated adding new element to some dimension with automated element name template?
example : i have the dimension called 'Product' which consist of
PDT001
PDT002
And i want to create a TI process where it will be creating a new dimension element with that "PDT002"(Current element) + 1
so it will be "PDT003" and so on everytime user run that process. Is it possible to do that? your help will be very helpful for me thank you all
------------------------------
calvin winardi
------------------------------