When building views, from time to time you might require attributes/properties on the view to be populated from other sources such as adapters (or other views). While there is a checkbox in Service Configuration Manager to copy properties, this only works if you have an exact match based on spelling and case sensitivity. For those cases where they do not match, or you require additional logic (get TCP/IP address from source3 first, otherwise get it from source2), the approach to solving this challenge is via java script.

The most simplistic solution (and the one that will cause the most log file errors) is to do something like

element[ 'TCP/IP Address' ] = structure[ "IP Address"]

While this will work, the reason it will cause lots of errors to the log files is that Service configuration manager calls the scripting multiple times and some context checks need to be put into place such as verifying the objects exists (element, structure, etc) prior to using them.

One approach I have used over the years is to use a script that only requires edits at the top prior to using it.

The first part of the script declares a couple of arrays. The arrays will hold the name of the attribute we want to get, the name of the attribute we want to set and the location of the attribute (on the structure or the source)

var pullFrom = new Array()
var pullLocation = new Array()
var putInto = new Array()

pullFrom[ 0 ] = 'IP_Address'
pullLocation[ 0 ] = 'structure'
putInto[ 0 ] = 'TCP/IP Address'

pullFrom[ 1 ] = 'MAC'
pullLocation[ 1 ] = 'source'
putInto[ 1 ] = 'MAC Address'

The only thing that needs editted is the above section. The section below is the chunk of code that does the work.

for( var i=0; i<pullFrom.length; i++ )
{
 	switch( pullLocation[ i ] ){

		case 'structure':
			if( structure && element && structure[ pullFrom[i] ] && element[ putInto[i] ] )
			{
				element[ putInto[ i ] ] = structure[ pullFrom[i] ];
			}
			break;
		case 'source':
			if( this.source && element && this.source[ pullFrom[i] ] && element[ putInto[i] ] )
			{
				element[ putInto[ i ] ] = this.source[ pullFrom[i] ];
			}
			break;
	}
}
  • The script starts off with a for loop. It uses the pullFrom array to determine how many attirbutes/properties are going to be set (make sure all arrays have the same amount of entries or the script will go boom)
  • The next part of the script uses a case statement to switch on the location of the attribute (structure/source).
  • Within each case section, it first verifies that the source location exists, an element was created by Service Configuration Manager in the final view, then it checks to see if the pull from attribute and put into attributes exists. If all that checks out, the element property is set.
  • That is the entire script. I’m sure there are endless ways to do this type of script, this is just the way I have done it.

    For ease of copy/paste, here is the entire script

    var pullFrom = new Array()
    var pullLocation = new Array()
    var putInto = new Array()
    
    pullFrom[ 0 ] = 'IP_Address'
    pullLocation[ 0 ] = 'structure'
    putInto[ 0 ] = 'TCP/IP Address'
    
    pullFrom[ 1 ] = 'MAC'
    pullLocation[ 1 ] = 'source'
    putInto[ 1 ] = 'MAC Address'
    
    
    for( var i=0; i<pullFrom.length; i++ )
    {
     	switch( pullLocation[ i ] ){
    
    		case 'structure':
    			if( structure && element && structure[ pullFrom[i] ] && element[ putInto[i] ] )
    			{
    				element[ putInto[ i ] ] = structure[ pullFrom[i] ];
    			}
    			break;
    		case 'source':
    			if( this.source && element && this.source[ pullFrom[i] ] && element[ putInto[i] ] )
    			{
    				element[ putInto[ i ] ] = this.source[ pullFrom[i] ];
    			}
    			break;
    	}
    }
    
    0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
    You need to be a registered member to rate this post.
    Loading...Loading...
    Categories: Uncategorized

    Disclaimer: As with everything else at NetIQ Cool Solutions, this content is definitely not supported by NetIQ, so Customer Support will not be able to help you if it has any adverse effect on your environment.  It just worked for at least one person, and perhaps it will be useful for you too.  Be sure to test in a non-production environment.

    Leave a Reply

    No Comments
    Jan 27, 2011
    12:10 pm
    Reads:
    1,300
    Score:
    Unrated