I am trying to design a TM1 TI code method to delete subsets from a given dimension where not all of the subset name is specified.
Its not that I don't know all of the name, but that the name is generated in TI by a combination of multiple user-entered variables (up to 7) to make it unique and I would like to just pick one variable to use to delete a set of subsets rather than searching through all of the combinations to define the name, see if it exists and then delete it.
So, any ideas?...can I pass a partial name with a wildcard to SubsetDestroy()?
Destroying subsets by wildcard search?
Re: Destroying subsets by wildcard search?
It might be best if you give an example - and indicate whether or not that will be the only case...
For example you might want to find "string1" anywhere inside "string2" or you might want to use a more complex regex.
For example you might want to find "string1" anywhere inside "string2" or you might want to use a more complex regex.
-
- Regular Participant
- Posts: 152
- Joined: Fri May 23, 2008 12:08 am
- OLAP Product: TM1 CX
- Version: 9.5 9.4.1 9.1.4 9.0 8.4
- Excel Version: 2003 2007
- Location: Melbourne, Australia
- Contact:
Re: Destroying subsets by wildcard search?
You have to pass a valid subset name to SubsetDestroy, but you could ...
1/ use WildCardFileSearch to return the subset file name
2/ substring the returned value to remove ".sub"
3/ then SubsetDestroy
Make sure to delete any temp views that the subsets are used in first, otherwise you won't be able to delete the subsets. (You can use the same technique for cleaning unwanted views.)
1/ use WildCardFileSearch to return the subset file name
2/ substring the returned value to remove ".sub"
3/ then SubsetDestroy
Code: Select all
# what's the string we want to search for
pTempSubPrefix = 'YOUR_PREFIX_NAMING_CONVENTION_HERE';
# full path to where we want to look for subsets
vFileSearch = cServerPath | sDim | '}subs\' | pTempSubPrefix | '*.sub' ;
# find all subsets beginning with prefix if this dim folder exists
iContinue = 1;
vPriorFileName = '';
While( iContinue =1 ) ;
vZFile = WildcardFileSearch( vFileSearch, vPriorFileName );
IF( vZFile @<> '' );
# check for the subset file object & trim the .sub to delete
vSubset = SubSt( vZFile, 1, Long( vZFile ) - 4 );
IF( SubsetExists( sDim, vSubset ) = 1 );
SubsetDestroy( sDim, vSubset );
EndIF;
# look for next z subset after this one
vPriorFileName = vZFile;
Else;
# no more subset files beginning with prefix
iContinue = 0;
EndIF;
End;