#region Prolog #Region CallThisProcess
A snippet of code provided as an example how to call this process should the developer be working on a system without access to an editor with auto-complete.
If( 1 = 0 ); ExecuteProcess( '}bedrock.cube.view.delete', 'pLogOutput', pLogOutput, 'pStrictErrorHandling', pStrictErrorHandling, 'pCube', '', 'pView', '', 'pDelim', '&' ); EndIf; #EndRegion CallThisProcess
#*Begin: Generated Statements #End: Generated Statements
#################################################################################################
##Join the bedrock TM1 community on GitHub https://github.com/cubewise-code/bedrock Ver 4.0.0##
#################################################################################################
#Region @DOC
- To delete views from multiple cubes specify each cube name separated by a delimiter e.g. Sales&Inventory&Cashflow.
- If any invalid cubes are specified they will be skipped but the process will continue to process the other cubes.
- To delete multiple views specify each view name separated by a delimiter e.g. SalesByProduct&SalesByManager&SalesByStore.
- When specifying view names wildcards are permitted and all views that match the wildcard search string will be deleted.
- To specify multiple search stings list them all separated by a delimiter e.g. Bedrock*;*Temp;Test.
- Specific view names and wildcard based names can both be used together e.g. SalesByProduct;Bedrock*.
#EndRegion @DOC
##Global Variables StringGlobalVariable('sProcessReturnCode'); NumericGlobalVariable('nProcessReturnCode'); nProcessReturnCode= 0;
cThisProcName = GetProcessName(); cUserName = TM1User(); cTimeStamp = TimSt( Now, '\Y\m\d\h\i\s' ); cRandomInt = NumberToString( INT( RAND( ) * 1000 )); cTempSubset = cThisProcName | '' | cTimeStamp | '' | cRandomInt; cTempFile = GetProcessErrorFileDirectory | cTempSubset | '.csv'; sMessage = ''; cMsgErrorLevel = 'ERROR'; cMsgErrorContent = 'User:%cUserName% Process:%cThisProcName% ErrorMsg:%sMessage%'; cLogInfo = 'Process:%cThisProcName% run with parameters pCube:%pCube%, pView:%pView%, pDelim:%pDelim%.' ;
IF( pLogoutput = 1 );
LogOutput('INFO', Expand( cLogInfo ) );
ENDIF;
nErrors = 0; cDimension = '}Cubes';
nErrors = 0;
If( Trim( pView ) @= '' ); sMessage = 'No views specified.'; nErrors = nErrors + 1; LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) ); EndIf;
If( Trim( pDelim ) @= '' ); pDelim = '&'; EndIf;
If( Trim( pCube ) @= '' ); sMessage = 'No cube specified.'; nErrors = nErrors + 1; LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) ); EndIf;
If( nErrors > 0 ); If( pStrictErrorHandling = 1 ); ProcessQuit; Else; ProcessBreak; EndIf; EndIf;
sCubes = pCube; nCubeDelimIndex = 1; sDelimiter = pDelim; sMdx = ''; While( nCubeDelimIndex <> 0 ); nCubeDelimIndex = Scan( sDelimiter, sCubes ); If( nCubeDelimIndex = 0 ); sCube = Trim( sCubes ); Else; sCube = Trim( SubSt( sCubes, 1, nCubeDelimIndex - 1 ) ); sCubes = Trim( SubSt( sCubes, nCubeDelimIndex + Long( sDelimiter ), Long( sCubes ) ) ); EndIf;
# Create subset of cubes using Wildcard to loop through cubes in pCube with wildcard
sCubeExp = '"'|sCube|'"';
sMdxPart = Expand('{TM1FILTERBYPATTERN( TM1SUBSETALL( [}Cubes] ), %sCubeExp% )}');
IF( sMdx @= '');
sMdx = sMdxPart;
ELSE;
sMdx = sMdx | ' + ' | sMdxPart;
ENDIF;
End;
If( SubsetExists( '}Cubes' , cTempSubset ) = 1 ); # If a delimited list of cube names includes wildcards then we may have to re-use the subset multiple times SubsetMDXSet( '}Cubes' , cTempSubset, sMDX ); Else; # temp subset, therefore no need to destroy in epilog SubsetCreatebyMDX( cTempSubset, sMDX, '}Cubes' , 1 ); EndIf;
# Loop through cubess in subset created based on wildcard
nCountCubes = SubsetGetSize( '}Cubes' , cTempSubset );
While( nCountCubes >= 1 );
sCurrentCube = SubsetGetElementName( '}Cubes' , cTempSubset, nCountCubes );
# If a valid cube has been specified then delete specified views from it
If( CubeExists( sCurrentCube ) = 1 );
If( pLogOutput = 1 );
LogOutput( 'INFO', Expand( 'Processing cube %sCurrentCube%.' ) );
EndIf;
# Work through all views specified in pViews
sViews = pView;
nViewDelimIndex = 1;
sMdxView = '';
While( nViewDelimIndex <> 0 );
nViewDelimIndex = Scan( sDelimiter, sViews );
If( nViewDelimIndex = 0 );
sView = Trim( sViews );
Else;
sView = Trim( SubSt( sViews, 1, nViewDelimIndex - 1 ) );
sViews = Trim( SubSt( sViews, nViewDelimIndex + Long( sDelimiter ), Long( sViews ) ) );
EndIf;
# Check if a wildcard has been used to specify the view name.
# If it hasn't then just delete the view if it exists
If( Scan( '*', sView ) = 0 );
If( ViewExists( sCurrentCube, sView ) = 1 );
If( pLogOutput = 1 );
LogOutput( 'INFO', Expand( ' Destroying view %sView% in cube %sCurrentCube%.' ) );
EndIf;
ViewDestroy( sCurrentCube, sView );
EndIf;
# If it has then iterate through '}Views_CubeName' dimension
Else;
sDimViews = '}Views_' | sCurrentCube ;
If( DimensionExists( sDimViews ) = 1 );
# Create subset of views using Wildcard to loop through views in current cube
sViewExp = '"'|sView|'"';
sMdxViewPart = Expand('{TM1FILTERBYPATTERN( {TM1SUBSETALL([%sDimViews%])}, %sViewExp% )}');
IF( sMdxView @= '');
sMdxview = sMdxViewPart;
ELSE;
sMdxView = sMdxView | ' + ' | sMdxViewPart;
ENDIF;
If( SubsetExists( sDimViews, cTempSubset ) = 1 );
# If a delimited list of attr names includes wildcards then we may have to re-use the subset multiple times
SubsetMDXSet( sDimViews, cTempSubset, sMdxView );
Else;
# temp subset, therefore no need to destroy in epilog
SubsetCreatebyMDX( cTempSubset, sMdxView, sDimViews, 1 );
EndIf;
# Loop through subset of views created based on wildcard
nCountView = SubsetGetSize( sDimViews, cTempSubset );
While( nCountView >= 1 );
sViewEle = SubsetGetElementName( sDimViews, cTempSubset, nCountView );
# Validate attribute name in sDim
If( ViewExists( sCurrentCube, sViewEle ) = 1 );
If( pLogOutput = 1 );
LogOutput( 'INFO', Expand( 'Destroying view %sViewEle% in cube %sCurrentCube%.' ) );
EndIf;
ViewDestroy( sCurrentCube, sViewEle );
Endif;
nCountView = nCountView - 1;
End;
EndIf;
EndIf;
End;
# Cube does not exist
Else;
sMessage = Expand('Cube %sCurrentCube% does not exist.');
LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) );
EndIf;
nCountCubes = nCountCubes - 1;
End;
#endregion #region Metadata
#*Begin: Generated Statements #End: Generated Statements #endregion #region Data
#*Begin: Generated Statements #End: Generated Statements #endregion #region Epilog
#*Begin: Generated Statements #End: Generated Statements
#################################################################################################
##Join the bedrock TM1 community on GitHub https://github.com/cubewise-code/bedrock Ver 4.0##
#################################################################################################
If( nErrors > 0 );
sMessage = 'the process incurred at least 1 error. Please see above lines in this file for more details.';
nProcessReturnCode = 0;
LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) );
sProcessReturnCode = Expand( '%sProcessReturnCode% Process:%cThisProcName% completed with errors. Check tm1server.log for details.' );
If( pStrictErrorHandling = 1 );
ProcessQuit;
EndIf;
Else;
sProcessAction = Expand( 'Process:%cThisProcName% successfully deleted view %pView% from cube %pCube%.' );
sProcessReturnCode = Expand( '%sProcessReturnCode% %sProcessAction%' );
nProcessReturnCode = 1;
If( pLogoutput = 1 );
LogOutput('INFO', Expand( sProcessAction ) );
EndIf;
EndIf;
#endregion