CdmQuery - Scoped
-
- UpdatedJan 30, 2025
- 14 minutes to read
- Yokohama
- API reference
The CdmQuery script include provides methods that enable you to query the CDM data model tree. It returns a list of node objects that are specific fields/columns in the CDM Node [sn_cdm_node] table. These values are returned as properties in the object. Every object is a node in the data model.
This script include is fluent which means most of its methods support chaining and return a CdmQuery object. The methods within this script include are classified into different types. You must specify them in a particular order within a call, based on their type. All methods except the result methods are chainable.
- entry method: This method specifies the entry node. CdmQuery limits its query to the entry node and its descendant nodes. Specifying the entry node is mandatory.
- query method: This method executes the specified query.
- result methods: These methods return a specific set of results data.
- setting methods: These methods modify the behavior of CdmQuery().
The snapshotId() and query() methods are mandatory. You must add filter and setting methods before the query() method, but after the snapshotId() method. The order in which you add filter and setting methods is not important, unless they are conflicting, in which case the latest relevant method prevails. You must add any result methods, such as getTree() to fetch the result, after the query() method.
This API runs in the sn_cdm
namespace and you must have the sn_cdm.cdm_viewer or sn_cdm.cdm_secrets roles to access its various methods.
CdmQuery - CdmQuery()
Instantiates a CdmQuery object. You must call this method prior to calling any other CdmQuery methods.
Name | Type | Description |
---|---|---|
None |
Example
The following code examples shows how to call the CdmQuery method to instantiate a CdmQuery object in the sn_cdm namespace.
CdmQuery - decryptPassword(Boolean decrypt)
Enables you to specify whether decrypted values for encrypted configuration data item (CDI) and variable nodes are returned in the results.
An error is thrown if the user does not have the required sn_cdm.cdm_secrets role.
Name | Type | Description |
---|---|---|
decrypt | Boolean | Optional. Flag that indicates whether to return decrypted values for the CDI and variable nodes. Valid values:
Default: false |
Type | Description |
---|---|
None |
Example
The following code example shows how to call the CdmQuery() API and specify to return encrypted values for the CDI and variable nodes.
Return results:
Example
The following code example shows how to call the CdmQuery() API and specify to return decrypted values for the CDI and variable nodes.
Return results:
CdmQuery - followIncludes(Boolean followIncludes)
Enables you to specify whether linked nodes are fully resolved, such that descendant nodes of a referenced node appear under a linked node.
Name | Type | Description |
---|---|---|
followIncludes | Boolean | Optional. Flag that indicates whether linked nodes are fully resolved. Valid values:
Default: true |
Type | Description |
---|---|
None |
Example
The following code example shows how to return data that is fully resolved, followIncludes = true.
Example return data:
Example
The following code example shows how to return data that is not fully resolved, followIncludes = false.
Example return data:
CdmQuery - forEach(Function function)
Iterates through each of the result nodes and applies the provided function that accepts a CdmNode object.
Name | Type | Description |
---|---|---|
function | Function | Function to apply to the CdmNode object. |
Type | Description |
---|---|
None |
Example
This code example shows how to call the forEach() method.
CdmQuery - getTree(Boolean simpleTree, Boolean prettify)
Returns the specified CDM query results.
You can specify the level and format of the content to return by setting the associated flags within the call. The default is to return a formatted string containing the node metadata and its child nodes, and where the entry node is the top node.
Name | Type | Description |
---|---|---|
simpleTree | Boolean | Optional. Flag that indicates the level of content to return. Valid values:
Default: false |
prettify | Boolean | Optional. Flag that indicates whether to return a formatted string instead of a JSON object. Valid values:
Default: false |
Type | Description |
---|---|
CdmQuery | CdmQuery object containing the specified query information. |
Example
The following code example shows how to call the getTree() method using the default settings. This returns a formatted string containing the node metadata and all its child nodes.
Return results:
Example
The following code example shows how to call the getTree() method to return a simplified JSON object of hierarchical key-values pairs.
Return results:
Example
The following code example shows how to call the getTree() method to return a JSON object containing the node metadata and all its child nodes.
Return results:
CdmQuery - getValue(String fieldName)
Returns the value of the specified field of the current iterated node result.
Name | Type | Description |
---|---|---|
fieldName | String | Name of the field with the snapshot record to return. |
Type | Description |
---|---|
None |
Example
The following code example shows how to use the getValue() method to extract required data.
Return values:
CdmQuery - includeFileMetadata()
Enables you to specify whether to fetch the file metadata information for file nodes. The file metadata contains attachment_id, file_name, content_type, and checksum.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
None |
Example
The following code example shows how to call the CdmQuery() API and return file metadata information.
Returns:
CdmQuery - next()
Iterates to the next node result and returns it if it exists.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
CdmQuery | If available, the CdmQuery object of the next node. If no additional nodes are available it returns a null or undefined. |
Example
The following code example shows how the next() method to iterate through the available node.
Return results:
CdmQuery - query()
Executes the specified query against the CDM database or the cache based on the settings, entry node, and filter settings.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
CdmQuery | CdmQuery object. |
Example
The following code example shows how to call the CdmQuery() API and specify the deployable snapshot to query.
Return results:
CdmQuery - snapshotId(String snapshotSysID)
Specifies the entry node. The CdmQuery API limits its query to the entry node and its descendant nodes. Calling this method is mandatory.
Name | Type | Description |
---|---|---|
snapshotSysId | String | Sys_id of the deployable snapshot to query. Internally it sets the sys_id of the changeset and the sys_id of the deployable node. Table: CDM Snapshot [sn_cdm_snapshot] |
Type | Description |
---|---|
None |
Example
The following code example shows how to call the CdmQuery() API and specify the deployable snapshot to query.
Return results:
CdmQuery - substituteVariable(Boolean substitute)
Enables you to specify whether to substitute variable references in configuration data item (CDI) nodes with the value of the referenced variable node.
Name | Type | Description |
---|---|---|
substitute | Boolean | Optional. Flag that indicates whether to substitute variable references in CDI nodes with the value of the referenced variable node. Valid values:
Default: true |
Type | Description |
---|---|
None |
Example
The following code examples shows how to turn off substitution of variable references in CDI nodes.
Example return results:
Example
The following code examples shows how to turn on substitution of variable references in CDI nodes and the associated return results for the same record.
Example return results:
CdmQuery - useCache(Boolean useCache)
Enables you to specify whether to retrieve data from the cache, if any, instead of querying the database.
Name | Type | Description |
---|---|---|
useCache | Boolean | Optional. Flag that indicates whether to retrieve data from the cache, if any, instead of querying the database. Valid values:
Default: true |
Type | Description |
---|---|
None |
Example
The following code examples shows how to turn off using the cache to obtain data.
On this page
- CdmQuery - CdmQuery()
- CdmQuery - decryptPassword(Boolean decrypt)
- CdmQuery - followIncludes(Boolean followIncludes)
- CdmQuery - forEach(Function function)
- CdmQuery - getTree(Boolean simpleTree, Boolean prettify)
- CdmQuery - getValue(String fieldName)
- CdmQuery - includeFileMetadata()
- CdmQuery - next()
- CdmQuery - query()
- CdmQuery - snapshotId(String snapshotSysID)
- CdmQuery - substituteVariable(Boolean substitute)
- CdmQuery - useCache(Boolean useCache)