Try it out: Custom snippets tutorial
Work through this tutorial to understand the process of converting an existing process script to a reusable custom snippet.
About this task
This tutorial converts this example process script into a custom snippet.
# Iterate over members in a hierarchy
vDimension = 'null';
vHierarchy = 'null';
vSubset = 'temporary';
HierarchySubsetCreate(vDimension, vHierarchy, vSubset, 1);
HierarchySubsetIsAllSet(vDimension, vHierarchy, vSubset, 1);
index = 1;
vSubsetSize = HierarchySubsetGetSize(vDimension, vHierarchy, vSubset);
WHILE (index <= vSubsetSize);
vElement = ElementName(vDimension, vHierarchy, index);
IF ( ElementLevel(vDimension, vHierarchy, vElement) = 0);
# Do something with vElement such as a write it to a file
AsciiOutput('model_upload/snippet.txt', vElement);
ENDIF;
index = index + 1;
vElement = ElementName(vDimension, vHierarchy, index);
END;
The snippet you'll create in this tutorial prompts for variable values and then inserts the
resulting script into a process. The script iterates over all members in the specified hierarchy and
performs an action on each member. In this case, the script uses the
AsciiOutputFunction
to write each 0-level (leaf) member to the
snippet.txt file. You can insert the custom snippet that you create in this
tutorial into any new or existing process on your database and run it against any existing
hierarchy.
Procedure
Results
When you run the process, the process creates a temporary subset and iterates over each member. When the process encounters a 0-level member, it writes the member name to the snippet.txt file in the Planning Analytics Workspace file manager.
To review the file, right-click your database in the Databases tree on a modeling workbench, then click File manager. Select snippet.txt, then click Download. The file should contain all the 0-level members of the hierarchy you selected when you inserted the custom snippet into the process.