Searching the Help
To search for information in the Help, type a word or phrase in the Search box. When you enter a group of words, OR is inferred. You can use Boolean operators to refine your search.
Results returned are case insensitive. However, results ranking takes case into account and assigns higher scores to case matches. Therefore, a search for "cats" followed by a search for "Cats" would return the same number of Help topics, but the order in which the topics are listed would be different.
Search for | Example | Results |
---|---|---|
A single word | cat
|
Topics that contain the word "cat". You will also find its grammatical variations, such as "cats". |
A phrase. You can specify that the search results contain a specific phrase. |
"cat food" (quotation marks) |
Topics that contain the literal phrase "cat food" and all its grammatical variations. Without the quotation marks, the query is equivalent to specifying an OR operator, which finds topics with one of the individual words instead of the phrase. |
Search for | Operator | Example |
---|---|---|
Two or more words in the same topic |
|
|
Either word in a topic |
|
|
Topics that do not contain a specific word or phrase |
|
|
Topics that contain one string and do not contain another | ^ (caret) |
cat ^ mouse
|
A combination of search types | ( ) parentheses |
|
- List: JavaScript functions in the ScriptLibrary
- JavaScript function: addToGroup
- JavaScript function: checkAllowedOption
- JavaScript function: checkVersionString
- JavaScript function: isfileexist
- JavaScript function: isInGroup
- JavaScript function: removeFromGroup
- JavaScript function: returnGroupMembers
- JavaScript function: returnMyGroups
- JavaScript function: skipApproval
JavaScript function: addToGroup
This function adds one or more configuration items (CIs) to a Configuration Management list group and updates the list group record if successful. It is part of a system JavaScript and should not be directly modified.
Syntax
lib.ciGrouping.addToGroup( ci, groupName );
Arguments
The following arguments are valid for this function:
Name | Data type | Required | Description |
---|---|---|---|
ci
|
Datum object or string | Yes | This argument contains the CI records you want to add. To add an array of CIs, the ci argument must be an SCFile or SCDatum object. To add a single CI, you can specify it as a string. |
groupName
|
String | Yes | This argument contains the name of the configuration group to which you want to add CIs. |
Return values
A numerical value: 0
or 1
.
The function returns 0
if it is unable to add CIs to the list group or if the groupName argument specifies a query group. The function returns 1
if the function successfully adds the CIs to the list group.
Example
This example attempts to add CIs to a list group from the following sources:
- The logical.name value from a hard-coded string
- The logical.name value from a configuration group record
- The logical.name values from an array of CI records
- The logical.name values from a record list of one or more CIs
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 variables to store CI group names, strings, and datum objects. * Use targetCIGroup to store the name of CI group you want to add records to. * Use sourceCIGroup to store the name of CI group you want to create an array from. * Use oneLogicalName to store a string containing a logical.name you want to add. * Use deviceType to store a device type you want to query for. * Use startsWith to store a alphabetical value you want to query for. * The variable recordTest stores the output of the findCIGroup function. * The variable arrayTest stores the output of the createArray function. * The variable recordListTest stores the output of the findRecordList function. */ var targetCIGroup; var sourceCIGroup; var oneLogicalName; var deviceType; var startsWith; var recordTest; var arrayTest; var recordListTest; /* Create a function to store a particular CI group in memory. */ function findCIGroup( ciGroup ) { print( "Looking for CI Group " + ciGroup + "..." ); var members = lib.ciGrouping.returnGroupMembers( ciGroup ) var ciGroupRecord = new SCFile( "cigroup" ); var queryTest = ciGroupRecord.doSelect( "logical.name=\"" + ciGroup + "\"" ) if ( queryTest == RC_SUCCESS ) { system.vars.$L_file = ciGroupRecord print( "Found CI group record for " + ciGroup + "\nThe record is:\n" + ciGroupRecord ); print( "The current members of " + ciGroup + " are:\n" + members ); return ciGroupRecord } else { print( "Cannot find record for " + ciGroup + ". " + RCtoString( queryTest ) + "." ); return null; } } /* Create function to find a record list based on a device type and starting query */ function findRecordList( deviceType, query ) { var ciRecordList = new SCFile( "device" ); if ( query != null ) { print( "Looking for CIs matching type=\"" + deviceType + "\"\&" + "logical.name#\"" + query + "\"" ); var queryTest = ciRecordList.doSelect( "type=\"" + deviceType + "\"\&" + "logical.name#\"" + query + "\"" ) } else { print( "Looking for CIs matching type=\"" + deviceType + "\"" ); var queryTest = ciRecordList.doSelect( "type=\"" + deviceType + "\"" ) } if ( queryTest == RC_SUCCESS ) { print( "Found the following CIs:\n" + ciRecordList ); system.vars.$L_file = ciRecordList return ciRecordList; } else { if ( query != null ) { print( "Cannot find records matching query: device=\""+ deviceType + "\"&logical.name#\"" + query + "\"" + RCtoString( queryTest ) + "." ); return null; } else { print( "Cannot find records matching query: device=\""+ deviceType + "\"" + RCtoString( queryTest ) + "." ); return null; } } } /* Create a function to store the logical.names of the record. */ function createArray( record ) { var arrayOfLogicalNames = record.group_members; if (arrayOfLogicalNames == null ) { print( "Cannot create array from " + record + ". Group not in the cigroup table." ); return null } else { print( "Created array from " + record + ".\nThe array is:\n" + arrayOfLogicalNames ); return arrayOfLogicalNames } } /* Create a function to call the addToGroup function and print results. */ function testAdd( ci, group ) { var groupMembers = lib.ciGrouping.returnGroupMembers( group ) var AddCI = lib.ciGrouping.addToGroup( ci, group ); var afterAdd = lib.ciGrouping.returnGroupMembers( group ); print( "Now trying to add configuration item(s) to " + group + "..." ); print( "The current members of " + group + " are:\n" + groupMembers ); if ( AddCI == 1 ) { print( "Successfully added configuration item(s) to " + group ); print( "The members of " + group + " are now: \n" + afterAdd ); } else { print( "Could not add configuration item(s) to " + group ); print( "The members of " + group + "are : \n" + groupMembers ); } } /* Test adding a CI to a group from a string */ print( "Now testing adding a single CI from a string...\n" ); targetCIGroup = "test01"; oneLogicalName = "DEFAULT Phone 0002"; members = lib.ciGrouping.returnGroupMembers( targetCIGroup ) testAdd( oneLogicalName, targetCIGroup ); /* Test adding a CI to a group from an existing CI record */ print( "Now testing adding a CI member from a CI group record...\n" ); targetCIGroup = "test01"; sourceCIGroup = "test02"; recordTest = findCIGroup( sourceCIGroup ); if ( recordTest != null ) { testAdd( system.vars.$L_file, targetCIGroup ); } /* Test adding one or more CIs from an array of logical,names */ print( "Now testing adding one or more CIs from an array of logical names...\n" ); targetCIGroup = "test01"; sourceCIGroup = "test03"; recordTest = findCIGroup( sourceCIGroup ); if ( recordTest != null ) { arrayTest = createArray( recordTest ); testAdd( arrayTest, targetCIGroup ); } /* Test adding one or more CIs to a group from a CI record list */ print( "Now testing adding one or more CIs from a CI record list...\n" ); targetCIGroup = "test01"; deviceType = "furnishings" startsWith = null; recordListTest = findRecordList( deviceType, startsWith ); if ( recordListTest != null ) { testAdd( system.vars.$L_file, targetCIGroup ); }