Anonymous_User Absent Member.
Absent Member.
457 views

Use Relationships in scripts


Hello,

How I can use relationships in my scripts? When I try to get the objects
which this object has relations with I receive only the parent object.
The script examples will be really helpful.
Thanks for advance.


--
Strakhov
------------------------------------------------------------------------
Strakhov's Profile: https://forums.netiq.com/member.php?userid=2637
View this thread: https://forums.netiq.com/showthread.php?t=46237

Labels (1)
0 Likes
6 Replies
Anonymous_User Absent Member.
Absent Member.

Re: Use Relationships in scripts


relationship methods are not published within the API at this time. In
order to do it, you will need to work with support for the base methods
as well as getting a signed script. I think the core methods you are
looking for are...

Add-> new Packages.com.mosol.Formula.Common.view.RelationshipValue(
RelationTypeToAdd, destEle.getId(), fromEle.getId(), null );
Remove-> elementLeft.removeRelationship( relationships[pos] );

I have not validated these calls, but I'm pretty sure these are the
internal methods that are used to add and/or remove relationships. The
remove requires more work, ie: you have to traverse through the
relationships on an element looking for the specific one to remove and
then you call removeRelationship on that item in the for/loop.


--
tisenberg
------------------------------------------------------------------------
tisenberg's Profile: https://forums.netiq.com/member.php?userid=1851
View this thread: https://forums.netiq.com/showthread.php?t=46237

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: Use Relationships in scripts


Thank you for answering.
But currently I'm not aware of how to get an object through
relationship. For example, I have the objects A and B with Relationship
'connected' between them. How to get B if I know A?


--
Strakhov
------------------------------------------------------------------------
Strakhov's Profile: https://forums.netiq.com/member.php?userid=2637
View this thread: https://forums.netiq.com/showthread.php?t=46237

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: Use Relationships in scripts


I would like to see a fragment of the script that is pulling back the
relationship details. What I do remember when I scripted to this many
years ago, the relationship shows up on an element as a type of link.
When you decode the linked 'element' (which it is not), you end up with
a relationship type and two dnames. You can formula.root.findElement()
on the dames.


--
tisenberg
------------------------------------------------------------------------
tisenberg's Profile: https://forums.netiq.com/member.php?userid=1851
View this thread: https://forums.netiq.com/showthread.php?t=46237

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: Use Relationships in scripts


tisenberg;222656 Wrote:
> I would like to see a fragment of the script that is pulling back the
> relationship details. What I do remember when I scripted to this many
> years ago, the relationship shows up on an element as a type of link.
> When you decode the linked 'element' (which it is not), you end up with
> a relationship type and two dnames. You can formula.root.findElement()
> on the dames.


Yes, I'll like to see your code too ^)
The only code helping me to get something here:

formula.log.info("conditionState.elements.size="+conditionState.elements.size());
if (conditionState.elements.size()>0)
{
for( var aaa = conditionState.getElements().elements();
aaa.hasMoreElements(); )
{
try{
var child = aaa.nextElement();
formula.log.info("child element through
conditionState="+child.getName());
}catch(e){formula.log.info("Error in finding something in
conditionState's el :"+e);}
}
}


--
Strakhov
------------------------------------------------------------------------
Strakhov's Profile: https://forums.netiq.com/member.php?userid=2637
View this thread: https://forums.netiq.com/showthread.php?t=46237

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: Use Relationships in scripts


Here is what I found out... (Keep in mind that I have not set this up
to validate, but it does look familiar ie: I seem to remember using
these).

var relationshipValues = element.getRelationships()

var relationshipValues = element.getRelationshipsOfName( name )

relationshipValues.toString() to see the relationship field values (
or get each directly i.e. relationshipValues.rightDName or
relationshipValues.getRightDName())

so element.getRelatinships() is the main call, then a for loop to go
through relationshipValues. My guess is you'll do a toString to get
relationship type/name and do a call to get right and left

Keep in mind that your results may vary based on algorithms (hint the
developer told me). What I mean is, potentially if you have a custom
algorithm in place, the gather() may have more or less elements. I'm
not really aware of this part since I have not really encountered this
specific use case.


--
tisenberg
------------------------------------------------------------------------
tisenberg's Profile: https://forums.netiq.com/member.php?userid=1851
View this thread: https://forums.netiq.com/showthread.php?t=46237

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: Use Relationships in scripts


Yes. YES! This is exactly what I need. GREAT THANKS. I've checked it and
it works on my box (NOC 5.0)


--
Strakhov
------------------------------------------------------------------------
Strakhov's Profile: https://forums.netiq.com/member.php?userid=2637
View this thread: https://forums.netiq.com/showthread.php?t=46237

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.