JavaScript function: returnMyGroups

Returns an array containing all the groups to which a configuration item (CI) belongs.

Syntax

lib.ciGrouping.returnMyGroups( ci, listType );

Arguments

The following arguments are valid for this function:

Name Data type Required Description
ci String Yes This argument contains the CI record you want to search for in your list and query groups.
listType String No This argument contains a string describing which types of configuration groups you want the function to query. The string can have one of four values:
  • list: Add this argument to only search list groups.
  • query: Add this argument to only search query groups.
  • both: Add this argument to search both list and query groups.
  • null: If there is a null entry for this argument, the function searches both list and query groups.

Return values

An array of group names.

The function returns an array containing the logical.name values of the list and query groups in which the CI is a member. The function returns an empty array if it cannot find the CI in any list or query group.

Description

This function is part of a system JavaScript and should not be directly modified.

This function returns an array containing the logical.name values of the groups in which the CI is a member. The function queries all group records and does the following:

  • If the group is a list type, the function indexes the group.members and if the CI exists in the list group, adds it to the groupArray.
  • If the group is a query type, the function uses the RTE function to determine whether the values in the CI record satisfy the search criteria defined by the query.

Example

This example returns the groups containing the CI listed in a variable.

This example requires the following sample data:

  • Create a list group containing a single configuration item (for example, a list group called "test01" containing the configuration item "DEFAULT Phone 0001")
  • Create a list group containing one or more configuration items (for example, a list group called "test02" containing the configuration item "DEFAULT Phone 0003")
  • Create a list group containing one or more configuration items (for example, a list group called "test03" containing the configuration items "HH-000001" and "HH-000002")
  • Create a query group containing one or more configuration items (for example, a query group called "test04" containing the configuration items where type equals "telecom")
/* Create variables to store CI group name and the results of returnMyGroups */
var targetCIGroup;
var listTypes;
var groups;

/* Search for a CI in a list group only */
print( "Now testing search for configuration items in list groups only...\n" );
targetCI = "DEFAULT Phone 0001";
listTypes = "list";
groups = lib.ciGrouping.returnMyGroups( targetCI, listTypes );
if ( groups.length >= 1 )
{
 print( "The list groups containing " + targetCI + " are:\n" + groups );
}
else
{
 print( "There are no list groups containing " + targetCI );
}

/* Search for a CI in a query group only */
print( "Now testing search for configuration items in query groups only...\n" );
targetCI = "DEFAULT Phone 0001";
listTypes = "query";
groups = lib.ciGrouping.returnMyGroups( targetCI, listTypes );
if ( groups.length >= 1 )
{
 print( "The query groups containing " + targetCI + " are:\n" + groups );
}
else
{
 print( "There are no query groups containing " + targetCI );
}

/* Search for a CI in both list and query groups */
print( "Now testing search for configuration items in both list and query groups...\n" );
targetCI = "DEFAULT Phone 0001";
listTypes = "both";
groups = lib.ciGrouping.returnMyGroups( targetCI, listTypes );
if ( groups.length >= 1 )
{
 print( "The groups containing " + targetCI + " are:\n" + groups );
}
else
{
 print( "There are no groups containing " + targetCI );
}