SubsetService
import { SubsetService } from "@skipcheck/tm1-client"; Subsets: a hierarchy's public, private and session subsets (SubsetScope), their
elements, and the operations bound to a subset or creating a session subset.
A static subset lists its elements; a dynamic one has an MDX Expression.
Binding Elements in a subset PATCH appends to them, so update
refuses it: addElements appends by name and clearElements empties the
list.
Create a static subset, binding its elements:
// A static subset lists its elements, bound by their paths
const elements = ODataPath.of("Dimensions").key("Region").nav("Hierarchies").key("Region").nav("Elements");
const keyRegions = SubsetPatch.builder().name("Key Regions").bindElements(elements.key("North"), elements.key("South")).build();
return tm1.subsets.create("Region", "Region", SubsetScope.Public, keyRegions);
Create a dynamic subset from an MDX expression:
// A dynamic subset has an MDX expression, evaluated each time it's read
const allLeaves = SubsetPatch.builder().name("All Leaves").expression("{TM1FILTERBYLEVEL({TM1SUBSETALL([Region].[Region])}, 0)}").build();
return tm1.subsets.create("Region", "Region", SubsetScope.Public, allLeaves);
Replace a static subset's elements:
// A PATCH appends elements, so empty the list, then add the new ones in order
await tm1.subsets.clearElements("Region", "Region", SubsetScope.Public, "Key Regions");
await tm1.subsets.addElements("Region", "Region", SubsetScope.Public, "Key Regions", ["East", "West"]);
Create a session subset and read its elements by the name TM1 gave it:
// TM1 names a session subset itself, ignoring the name sent: read it by the name it
// gives back
const regions = SubsetPatch.builder().name("Regions").expression("{[Region].[Region].[Total].Children}").build();
const subset = await tm1.subsets.createSessionSubset("Region", "Region", regions);
const elements = await tm1.subsets.elements("Region", "Region", SubsetScope.Session, subset.Name!, ODataQuery.none().select(Element.Fields.Name)).toArray();
return elements.map((element) => element.Name!);
Members
list | GET …/Hierarchies('h')/Subsets (or the private or session ones), streamed. |
get | The subset, or a Tm1NotFoundException if there's none. |
create | Creates a subset. |
update | Changes the properties the patch sets, such as a dynamic subset's expression. |
addElements | PATCH …/Subsets('s') binding Elements. |
clearElements | Removes every element from a static subset; the elements stay in the hierarchy. |
delete | DELETE …/Subsets('s'). |
elements | GET …/Subsets('s')/Elements, streamed. |
hierarchy | The subset's hierarchy. |
saveAs | Copies a subset under a new name. |
saveAs | tm1.SaveAs, choosing whether the copy is private (makePrivate) and whether it's static, holding the elements the subset has now (makeStatic). |
saveAs | |
setElement | Adds an element to a static subset, last, or moves it there if it's in it. |
setElementBefore | tm1.SetElement with Before. |
setElementAfter | tm1.SetElement with After. |
createSessionSubset | tm1.CreateSessionSubset with a definition (an Expression, or bound Elements). |
createSessionSubsetFrom | tm1.CreateSessionSubset with a reference. |
list
list(dimension: string, hierarchy: string, scope: SubsetScope, query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<Subset>GET …/Hierarchies('h')/Subsets (or the private or session ones), streamed. TM1 (11.8) lists no session subsets, though each reads by the name createSessionSubset returned.
get
get(dimension: string, hierarchy: string, scope: SubsetScope, subset: string, query?: ODataQuery | null, options?: Tm1CallOptions): Promise<Subset>GET …/Subsets('s'): the subset, or a Tm1NotFoundException if there's none.
create
create(dimension: string, hierarchy: string, scope: SubsetScope, subset: SubsetPatch, options?: Tm1CallOptions): Promise<Subset>POST …/Subsets: creates a subset: static with Elements@odata.bind (SubsetPatch.builder().bindElements(…)), dynamic with an Expression. It needs a name; returns the subset as created.
update
update( dimension: string, hierarchy: string, scope: SubsetScope, subset: string, patch: SubsetPatch, etag?: string | null, options?: Tm1CallOptions, ): Promise<void>PATCH …/Subsets('s'): changes the properties the patch sets, such as a dynamic subset's expression. With etag (subset["@odata.etag"], from a read), sent as If-Match: only if the subset hasn't changed since, else a Tm1PreconditionFailedException. Throws a RangeError, at once and sending nothing, if the patch sets or binds Elements, which TM1 appends: use addElements or clearElements.
addElements
addElements(dimension: string, hierarchy: string, scope: SubsetScope, subset: string, elements: readonly string[], options?: Tm1CallOptions): Promise<void>PATCH …/Subsets('s') binding Elements: appends elements to a static subset, in order.
clearElements
clearElements(dimension: string, hierarchy: string, scope: SubsetScope, subset: string, options?: Tm1CallOptions): Promise<void>DELETE …/Subsets('s')/Elements/$ref: removes every element from a static subset; the elements stay in the hierarchy.
TM1 REST Navigation Subset/Elements
delete
delete(dimension: string, hierarchy: string, scope: SubsetScope, subset: string, options?: Tm1CallOptions): Promise<void>DELETE …/Subsets('s').
elements
elements(dimension: string, hierarchy: string, scope: SubsetScope, subset: string, query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<Element>GET …/Subsets('s')/Elements, streamed: a static subset's elements in order, or what a dynamic one's expression gives now.
TM1 REST Navigation Subset/Elements
hierarchy
hierarchy(dimension: string, hierarchy: string, scope: SubsetScope, subset: string, query?: ODataQuery | null, options?: Tm1CallOptions): Promise<Hierarchy>GET …/Subsets('s')/Hierarchy: the subset's hierarchy.
TM1 REST Navigation Subset/Hierarchy
saveAs
saveAs(dimension: string, hierarchy: string, scope: SubsetScope, subset: string, newName: string, options?: Tm1CallOptions): Promise<Subset>tm1.SaveAs: copies a subset under a new name. Without makePrivate and makeStatic the copy is public and keeps whether it's static or dynamic; with them, it's private if makePrivate, and static, holding the elements the subset has now, if makeStatic. Returns the copy.
TM1 REST Action Subset/SaveAs
saveAs
saveAs( dimension: string, hierarchy: string, scope: SubsetScope, subset: string, newName: string, makePrivate: boolean, makeStatic: boolean, options?: Tm1CallOptions, ): Promise<Subset>tm1.SaveAs, choosing whether the copy is private (makePrivate) and whether it's static, holding the elements the subset has now (makeStatic). Returns the copy.
TM1 REST Action Subset/SaveAs
saveAs
saveAs( dimension: string, hierarchy: string, scope: SubsetScope, subset: string, newName: string, makePrivate?: boolean | Tm1CallOptions, makeStatic?: boolean, options?: Tm1CallOptions, ): Promise<Subset>TM1 REST Action Subset/SaveAs
setElement
setElement(dimension: string, hierarchy: string, scope: SubsetScope, subset: string, element: string, options?: Tm1CallOptions): Promise<void>tm1.SetElement: adds an element to a static subset, last, or moves it there if it's in it.
TM1 REST Action Subset/SetElement
setElementBefore
setElementBefore( dimension: string, hierarchy: string, scope: SubsetScope, subset: string, element: string, before: string, options?: Tm1CallOptions, ): Promise<void>tm1.SetElement with Before: places an element just before another in a static subset.
TM1 REST Action Subset/SetElement
setElementAfter
setElementAfter( dimension: string, hierarchy: string, scope: SubsetScope, subset: string, element: string, after: string, options?: Tm1CallOptions, ): Promise<void>tm1.SetElement with After: places an element just after another in a static subset.
TM1 REST Action Subset/SetElement
createSessionSubset
createSessionSubset(dimension: string, hierarchy: string, definition: SubsetPatch, options?: Tm1CallOptions): Promise<Subset>tm1.CreateSessionSubset with a definition (an Expression, or bound Elements): creates a subset visible only to this session. TM1 (11.8) ignores the definition's Name and names it itself; the result has the name to use.
TM1 REST Action Hierarchy/CreateSessionSubset
createSessionSubsetFrom
createSessionSubsetFrom(dimension: string, hierarchy: string, scope: SubsetScope, subset: string, options?: Tm1CallOptions): Promise<Subset>tm1.CreateSessionSubset with a reference: copies a subset into one visible only to this session; the result has the name TM1 gave it.
TM1 REST Action Hierarchy/CreateSessionSubset