Please use docs.servicenow.com for the latest documentation.

This site is for reference purposes only and may not be accurate for the latest ServiceNow version

CMDBUtil API

From Wiki Archive
Jump to: navigation, search

This article applies to Fuji. For more current information, see CMDBUtil at https://developer.servicenow.com

The ServiceNow Wiki is no longer being updated. Please refer to the Developer Portal for the latest information.

{{Topic|Scripting Glide and Jelly

Overview

The CMDBUtil API provides utility methods for creating and managing table relationships in the configuration management database (CMDB) and managing CMDB baselines. CMDBUtil is a JavaScript-accessible ScriptableObject. The CMDBUtil API has dynamic and static methods. You access dynamic methods by creating a SNC.CMDBUtil object. You access static methods by using SNC.CMDBUtil global object to call the methods.

This example instantiates a CMDBUtil object: <source lang="javascript"> var cu = new SNC.CMDBUtil(); cu.baselineProposedChangesGenDIFF(current, action.get('sysparm_changeset')); </source>

This example calls a static method: <source lang="javascript"> var output = SNC.CMDBUtil.getAllChildrenOfAsCommaList('cmdb_ci_computer'); </source>

For more information on CMDB baselines, see Baseline CMDB.

Where To Use

Use these methods to manage CMDB table relationships and baselines.


Method Summary

Dynamic methods

Method Summary Description
processCIChange(event, target) Wraps the call to RelationshipEventProcessor(), which processes any changes to CI relationships.
processRelChange(event, current, relType, triplet) Wraps the call to RelationshipEventProcessor(), which processes any changes to CI relationships, with the specified type and triplet.
createCIRelationship(arg1, arg2, arg3, arg4, arg5) Creates the specified CI relationship.
removeCIRelationship(arg1, arg2, arg3, arg4, arg5) Deletes the specified CI relationship.
baselineProposedChangesGenDIFF(gr, changeSet) Generates the XML for proposed changes diff, and adds it to the corresponding task_ci record.
baselineProposedChangesApplyChanges(gr) Applies proposed changes in a task_ci record that represent an update set for all CIs associated with the task.
getCMDBViews() Gets all the records in the CMDB View [cmdb_view] table.

Static methods

Method Summary Description
reParentTable(table, oldParent, newParent) Changes the parent of the given table to the new parent.
getTables0(table) Gets a list of all the parents of a table.
getAllChildrenOfAsCommaList(table) Gets all the children of the specified table.
bootstrap(dictFile) Bootstraps the environment.


Method Detail

processCIChange(event, target)

Wraps the call to RelationshipEventProcessor(), which processes any changes to CI relationships.

Input Fields

Parameters:

  • event - (GlideRecord) The event record.
  • target - (GlideRecord) The target record.

Output Fields

Returns: void


processRelChange(event, current, relType, triplet)

Wraps the call to RelationshipEventProcessor(), which processes any changes to CI relationships, with the specified type and triplet.

Input Fields

Parameters:

  • event - (GlideRecord) The event record.
  • current - (GlideRecord) The current record, which is either the relation record or a user record if the current process is a deletion.
  • relType - (String) The type of relation that changed.
  • triplet - (String) The child, parent, and class name from the relation that changed.

Output Fields

Returns: void


createCIRelationship(arg1, arg2, arg3, arg4, arg5)

Creates the specified CI relationship using the specified invocation parameters. If called without the first parameter, passing only four parameters, defaults to the CI Relationship [cmdb_rel_ci] table.

Input Fields

Parameters:

  • arg1 - (String) The table name.
  • arg2 - (String) The parent field.
  • arg3 - (String) The child field.
  • arg4 - (String) The parent relationship descriptor.
  • arg5 - (Object) The child relationship descriptor.

Output Fields

Returns: void


removeCIRelationship(arg1, arg2, arg3, arg4, arg5)

Deletes the specified CI relationship. If called without the first parameter, passing only four parameters, defaults to the CI Relationship [cmdb_rel_ci] table.

Input Fields

Parameters:

  • arg1 - (String) The table name.
  • arg2 - (String) The parent field.
  • arg3 - (String) The child field.
  • arg4 - (String) The parent relationship descriptor.
  • arg5 - (Object) The child relationship descriptor.

Output Fields

Returns: void


baselineProposedChangesGenDIFF(gr, changeSet)

Generates the XML for proposed changes diff, and adds it to the corresponding task_ci record.

Input Fields

Parameters:

  • gr - (GlideRecord) The current GlideRecord that contains the collection of proposed changes.
  • changeSet - (String) The sysid of the task_ci record that represents the change set to use.

Output Fields

Returns: void

Example

<source lang="javascript"> //Where current is a GlideRecord and action is the current UI action var base = new SNC.CMDBUtil(); base.baselineProposedChangesGenDIFF(current, action.get('sysparm_changeset')); </source>


baselineProposedChangesApplyChanges(gr)

Applies proposed changes in a task_ci record that represent an update set for all CIs associated with the task.

Input Fields

Parameters:

  • gr - (GlideRecord) The collection of proposed changes in the change request (CHG).

Output Fields

Returns: void

Example

<source lang="javascript"> //Where current is a GlideRecord and action is the current UI action var base = new SNC.CMDBUtil(); base.baselineProposedChangesApplyChanges(current); </source>


reParentTable(table, oldParent, newParent)

Changes the parent of the given table to the new parent. This is a static method.

Input Fields

Parameters:

  • table - (String) The table to reparent.
  • oldParent - (String) The old parent.
  • newParent - (String) The new parent.

Output Fields

Returns: (boolean) true, if successful; otherwise, false.


getTables0(table)

Gets a list of all the parents of a table. This is a static method.

Input Fields

Parameters:

  • table - (String) The table name.

Output Fields

Returns: (ArrayList) a list of tables that are parents of the given table.


getAllChildrenOfAsCommaList(table)

Gets all the child tables of the specified table as a comma-separated list. This is a static method.

Input Fields

Parameters:

  • table - (String) The base table.

Output Fields

Returns: (String) a comma-separated list of sys_ids of tables extending the base table.

Example

<source lang="javascript"> //Where cmdv_ci_computer is a table. var output = SNC.CMDBUtil.getAllChildrenOfAsCommaList('cmdb_ci_computer'); gs.print(output); </source>


bootstrap(dictFile)

Bootstraps the environment, if necessary, by:

  • Creating the database.
  • Creating the system dictionary table.
  • Having the system dictionary table describe itself.

This is a static method.

Input Fields

Parameters:

  • dictFile - (String) The pathed file name of the dictionary to load.

Output Fields

Returns: void


getCMDBViews()

Gets all the records in the CMDB View [cmdb_view] table.

Input Fields

Parameters:

  • None

Output Fields

Returns: (ArrayList) the records in the CMDB View table.