How to get the target object?

Hi!

 

How can I get the target object of a give outgoing link? I have written this:

 

myObject = target outGoingLink

 

If I write as next step a for loop, 'myObject' is the first object in the module in which the foor loop operates and not the object to which points the given link to!

 

Where is the failure?


bandchef - Fri Nov 29 06:36:51 EST 2013

Re: How to get the target object?
pommCannelle - Fri Nov 29 08:15:29 EST 2013

( You have to ensure that the target module is open in order to avoid the null object as target ...
According to the DXL help, you can try something like :

Object o = current
Link lnk; ModName_ targetMod
for lnk in o->"*" do {
    targetMod = target lnk
    read(fullName(targetMod), true)
    // now you can use the target perm with an object !
    Object otherO = target l
}

Have fun ! ;) )

Re: How to get the target object?
bandchef - Fri Nov 29 08:24:23 EST 2013

pommCannelle - Fri Nov 29 08:15:29 EST 2013

( You have to ensure that the target module is open in order to avoid the null object as target ...
According to the DXL help, you can try something like :

Object o = current
Link lnk; ModName_ targetMod
for lnk in o->"*" do {
    targetMod = target lnk
    read(fullName(targetMod), true)
    // now you can use the target perm with an object !
    Object otherO = target l
}

Have fun ! ;) )

Object o = current
Link lnk; ModName_ targetMod
for lnk in o->"*" do {
    targetMod = target lnk
    read(fullName(targetMod), true)
    // now you can use the target perm with an object !
    Object otherO = target l
}

 

What do you mean in the last line with "target l"?

 

 

My code:

  1. for lnk_InnerOutLink1 in gobj_CurrentObject1 -> "*" do
  2. {
  3. //cast von ModName_ zu Module
  4. targetMod1 = target lnk_InnerOutLink1
  5. gmod_CurrentModule2 = read(fullName targetMod1, true)
  6. //setze Startobjekt
  7. gobj_CurrentObject2 = target lnk_InnerOutLink1
  8.  
  9.  
  10. //Schaltet Objekte von "LH" weiter
  11.  
  12. for gobj_CurrentObject2 in gmod_CurrentModule2 do
  13. ...

Re: How to get the target object?
bandchef - Fri Nov 29 08:29:21 EST 2013

Mhmhmmm. My code don't work und your code also don't work. The objects which where iterated by the last for Loop are beginning with the first object and not with the object the link points to!

Re: How to get the target object?
pommCannelle - Sat Nov 30 09:59:35 EST 2013

bandchef - Fri Nov 29 08:29:21 EST 2013

Mhmhmmm. My code don't work und your code also don't work. The objects which where iterated by the last for Loop are beginning with the first object and not with the object the link points to!

( have you tried to replace
Object otherO = target l
by
Object otherO = target lnk 
? )

 

Re: How to get the target object?
Mathias Mamsch - Sun Dec 01 13:31:12 EST 2013

bandchef - Fri Nov 29 08:29:21 EST 2013

Mhmhmmm. My code don't work und your code also don't work. The objects which where iterated by the last for Loop are beginning with the first object and not with the object the link points to!

In this post I once showed the way to properly iterate over the links in a module (which also works with baselines / links to baselines)

https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014702797&ps=25

Here is the cleaned up code with leaks of ModuleVersion removed:

Object o Link lnk

for o in entire current Module do
{
  // Outlinks can be iterated, since the source is already loaded
  for lnk in all o ->"*" do
  {
    // load target
    ModuleVersion mvTarget = targetVersion lnk
    Module modTarget = data mvTarget
    noError();

    if (null modTarget) modTarget = load(mvTarget,false)
    lastError();
    delete mvTarget

    if (null modTarget) { /* put error handling here! */; continue }  

    // get target object
    Object oTgt = target lnk
    if (null oTgt) { /* put error handling here! */; continue }

    if (isDeleted oTgt) { /* error handling here! */; continue }   

    print "Out: '" (oTgt."Object Text") "'\n"
  }

  // load source modules of in-link references
  LinkRef lr;
  for lr in all (o<-"*") do {
    ModuleVersion mvSource = sourceVersion lr
    Module modSrc = data mvSource
    noError();
    if (null modSrc) modSrc = load(mvSource,true)
    lastError();
    delete mvSource
  }  

  // Iterate in-links and navigate (source modules are now open)
  for lnk in all (o <-"*") do
  {
    Object oSrc = source lnk
    if (null oSrc) { /* error handling */; continue }
    if (isDeleted oSrc) { /* error handling */; continue }
    print "In: '"(oSrc."Object Text") "'\n"
  }
}

Maybe that helps, regards, Mathias

Re: How to get the target object?
bandchef - Mon Dec 02 08:38:57 EST 2013

Mathias Mamsch - Sun Dec 01 13:31:12 EST 2013

In this post I once showed the way to properly iterate over the links in a module (which also works with baselines / links to baselines)

https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014702797&ps=25

Here is the cleaned up code with leaks of ModuleVersion removed:

Object o Link lnk

for o in entire current Module do
{
  // Outlinks can be iterated, since the source is already loaded
  for lnk in all o ->"*" do
  {
    // load target
    ModuleVersion mvTarget = targetVersion lnk
    Module modTarget = data mvTarget
    noError();

    if (null modTarget) modTarget = load(mvTarget,false)
    lastError();
    delete mvTarget

    if (null modTarget) { /* put error handling here! */; continue }  

    // get target object
    Object oTgt = target lnk
    if (null oTgt) { /* put error handling here! */; continue }

    if (isDeleted oTgt) { /* error handling here! */; continue }   

    print "Out: '" (oTgt."Object Text") "'\n"
  }

  // load source modules of in-link references
  LinkRef lr;
  for lr in all (o<-"*") do {
    ModuleVersion mvSource = sourceVersion lr
    Module modSrc = data mvSource
    noError();
    if (null modSrc) modSrc = load(mvSource,true)
    lastError();
    delete mvSource
  }  

  // Iterate in-links and navigate (source modules are now open)
  for lnk in all (o <-"*") do
  {
    Object oSrc = source lnk
    if (null oSrc) { /* error handling */; continue }
    if (isDeleted oSrc) { /* error handling */; continue }
    print "In: '"(oSrc."Object Text") "'\n"
  }
}

Maybe that helps, regards, Mathias

Hi!

Thx for your info, but this is not a code which I search for. I have a for-loop:

Object globalObject

 

for lnk_InnerOutLink2 in gobj_CurrentObject2 -> * do

{

     //Here, I will get from lnk_InnerOutLink2 the actually object!

     //globalObject = object(lnk_InnerOutLink2) //e.g.

}

 

Are you understanding my problem? For your Information: The link Points to another Module, which the link comes from!

Re: How to get the target object?
Mathias Mamsch - Mon Dec 02 09:28:18 EST 2013

bandchef - Mon Dec 02 08:38:57 EST 2013

Hi!

Thx for your info, but this is not a code which I search for. I have a for-loop:

Object globalObject

 

for lnk_InnerOutLink2 in gobj_CurrentObject2 -> * do

{

     //Here, I will get from lnk_InnerOutLink2 the actually object!

     //globalObject = object(lnk_InnerOutLink2) //e.g.

}

 

Are you understanding my problem? For your Information: The link Points to another Module, which the link comes from!

Yes, so the code I posted is indeed what you need. I just noticed that the link "Object oTgt = target lnk" was still inside a comment (due to the problematic formatting issues from the old posts). So you only need this part:

  // Outlinks can be iterated, since the source is already loaded
  for lnk in all o ->"*" do
  {
    // load target
    ModuleVersion mvTarget = targetVersion lnk
    Module modTarget = data mvTarget
    noError();

    if (null modTarget) modTarget = load(mvTarget,false)
    lastError();
    delete mvTarget

    if (null modTarget) { /* put error handling here! */; continue }  

    // get target object
   
Object oTgt = target lnk
    if (null oTgt) { /* put error handling here! */; continue }

    if (isDeleted oTgt) { /* error handling here! */; continue }   

    print "Out: '" (oTgt."Object Text") "'\n"
  }

oTgt is the object you are looking for (target object of the link). o is the object that is the source of the outlink. But the above code is the proper way to iterate over the outlinks of an object, and reliably get a handle to the link target while handling the corner cases (stale links, module deleted, target object is deleted, no access, link goes to baseline, link comes from baseline, ...).

Regards, Mathias

Re: How to get the target object?
Lerates - Tue Jul 04 01:32:22 EDT 2017

Mathias Mamsch - Mon Dec 02 09:28:18 EST 2013

Yes, so the code I posted is indeed what you need. I just noticed that the link "Object oTgt = target lnk" was still inside a comment (due to the problematic formatting issues from the old posts). So you only need this part:

  // Outlinks can be iterated, since the source is already loaded
  for lnk in all o ->"*" do
  {
    // load target
    ModuleVersion mvTarget = targetVersion lnk
    Module modTarget = data mvTarget
    noError();

    if (null modTarget) modTarget = load(mvTarget,false)
    lastError();
    delete mvTarget

    if (null modTarget) { /* put error handling here! */; continue }  

    // get target object
   
Object oTgt = target lnk
    if (null oTgt) { /* put error handling here! */; continue }

    if (isDeleted oTgt) { /* error handling here! */; continue }   

    print "Out: '" (oTgt."Object Text") "'\n"
  }

oTgt is the object you are looking for (target object of the link). o is the object that is the source of the outlink. But the above code is the proper way to iterate over the outlinks of an object, and reliably get a handle to the link target while handling the corner cases (stale links, module deleted, target object is deleted, no access, link goes to baseline, link comes from baseline, ...).

Regards, Mathias

Hello Matthias,

I have read through your posts and i try something similar in my Doors Module.

I want to display the link Path of outgoing amd incoming links in an extra Attribute.

For that I made a small progam in DXL :

//////////////////////////////////////////////////////////////////////////////////////////

Object o
Link l
string ausgabe
 
for o in current do {
print "." //Aktivitätsanzeige
//All outgoing links
ausgabe = "" //init
for l in o ->"*" do {
if (ausgabe != ""){ //vor erste Zeile kein \n
 ausgabe = ausgabe "\n"
}  
//Collect characteristics
ausgabe = ausgabe fullName(target(l)) //Modulname von Target
ausgabe = ausgabe ":" targetAbsNo(l) ""
o."Outgoing_Links" = ausgabe 
 
//Alle incoming links
    ausgabe = "" //init
for l in o <-"*" do {
if (ausgabe != ""){ //vor erste Zeile kein \n
 ausgabe = ausgabe "\n"
}  
ausgabe = ausgabe fullName(target(l)) //Modulname von Target
ausgabe = ausgabe ":" targetAbsNo(l) ""
}
o."Incoming_Links" = ausgabe 
}
////////////////////////////////////////////////////////////////////////////

For all the outgoing links it works fine, but for the incoming links, the programm just posts the destination path (The collum it is right now, and not the path it comes from)

Can someone explaine my mistake to me?

I am thankful for any help 

Thanks Lerates

 

Für dein Hilfe wäre ich sehr dankbar :)

Re: How to get the target object?
Mathias Mamsch - Mon Jul 17 06:41:28 EDT 2017

Lerates - Tue Jul 04 01:32:22 EDT 2017

Hello Matthias,

I have read through your posts and i try something similar in my Doors Module.

I want to display the link Path of outgoing amd incoming links in an extra Attribute.

For that I made a small progam in DXL :

//////////////////////////////////////////////////////////////////////////////////////////

Object o
Link l
string ausgabe
 
for o in current do {
print "." //Aktivitätsanzeige
//All outgoing links
ausgabe = "" //init
for l in o ->"*" do {
if (ausgabe != ""){ //vor erste Zeile kein \n
 ausgabe = ausgabe "\n"
}  
//Collect characteristics
ausgabe = ausgabe fullName(target(l)) //Modulname von Target
ausgabe = ausgabe ":" targetAbsNo(l) ""
o."Outgoing_Links" = ausgabe 
 
//Alle incoming links
    ausgabe = "" //init
for l in o <-"*" do {
if (ausgabe != ""){ //vor erste Zeile kein \n
 ausgabe = ausgabe "\n"
}  
ausgabe = ausgabe fullName(target(l)) //Modulname von Target
ausgabe = ausgabe ":" targetAbsNo(l) ""
}
o."Incoming_Links" = ausgabe 
}
////////////////////////////////////////////////////////////////////////////

For all the outgoing links it works fine, but for the incoming links, the programm just posts the destination path (The collum it is right now, and not the path it comes from)

Can someone explaine my mistake to me?

I am thankful for any help 

Thanks Lerates

 

Für dein Hilfe wäre ich sehr dankbar :)

Why did you not use the code from above? Remember: For an IN-link the "target" that you are using is not the one you are looking for. For inlinks you are interested in the source! Regards, Mathias