I’ve been having some questions lately on how to create elements via the javascript interface, this feels like a good blog entry.

To start with, creating an element via javascript is handled in context of the server. So for a right click Operation, that means that the Operation type needs to be serverscript, for automations, it would need to be AutomationServer.

To create the element, you need the full dname to the element. There is no requirement to precreate the hiearchy, it can do that on the fly, but there are some caveats… of course :) (you may have to go back and add the ORG relationships/link to the parents)


newElement = server.getElement("computer_workstation=server2/org=My+View/root=Organizations" )

The line above creates a new variable called newElement. It then calls the server.getElement() method passing a dname to it. The end goal is to create an element called server2 with a class of computer_workstation, under the element called My View on the Org page (AKA: Service Models).

This method will throw an exception if it is unable to create it, otherwise the element created will be returned inside of newElement. (hint: use a try/catch block)

For this exercise, we will assume “My View” was already created. When we did the call to create the new server1 element, it does create it as a child, but it does not by default add the child element (server1) as something that impacts it’s parent (My View). If you require impact to go up the tree, then you need to do the following…

var children = newElement.parent.Children
children.push( newElement.dname )
newElement.parent.Children = children

The first line grabs the current list of children that impact the condition of the parent. The second line (children.push) adds the newly created element to the list. The last line then sets the new list on the parent. After running this section of code, the newly created element should then show up under Properties/Elements.

There are a few different types of relationships. By default, any child element (that is NOT linked) is a type of NAM. Linked children (IE: linking an element from an adapter to a view) are of type ORG. In the UI, when you create an element in the service model under another element, by default it creates both the NAM and ORG. If you want to create an element but don’t want the condition to propagate to the parent, you can use an algorithm to reduce the child out, or just remove the ORG relationship under Properties/Elements.

Since we are here, let’s go the other way now, let’s remove an element…

newElement.perform( session, 'LifeCycle|Delete', [], [])

If you want to delete an element other than the one we just created, it is a matter of using the findElement method (IE: theElement = formula.Root.findElement( “computer_workstation=server3.novell.com/org=View/root=Organizations” ) ), then issuing theElement.perform() on it instead.

As usual, I have provided information that may help you, or hurt you, please be careful and do this on a development system. Sometimes it is easier to play with some of these idea within the debugger.

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...

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
Oct 8, 2010
1:25 pm
Reads:
1,382
Score:
Unrated