Get Attribute from Outlinked Module

Hi,

Ive searched through the forums and found some similar threads about this but I cannot for the life of me get it to work.

I have my Parent Module (PM) which has outlinks to several modules (SRS, SDD, etc) for each object.

My dxl code currently pulls just the path of the outlinks and dumps it into excel. I want in addition to this, to display 3 other attributes, if it exists, from that linked module.

My current code does the following (in excel)
 

PM ID          Outlinks
P1.1           /Reqts/SRS
               /Reqts/SRS
               /Reqts/SDD
P1.2           /Reqts/SRS
P1.3           /Reqts/SRS

 


What I want is,

 

 

 

PM ID          Outlinks
P1.1           /Reqts/SRS ID Attr2 Attr3
               /Reqts/SRS ID Attr2 Attr3
               /Reqts/SDD ID Attr2 Attr3
P1.2           /Reqts/SRS ID Attr2 Attr3
P1.3           /Reqts/SRS ID Attr2 Attr3

 

 

 

for o in m do {
    col = 0
        row ++    
    
      for l in o -> "*" do {
 
        // NEED TO CALL LINK MODULES ATTRBUTE ID, ATTR2 and ATTR3 here and append it to sTargetPath
 
        string temp2 = sTargetPath
        sTargetPath = sTargetPath fullName(target l) (NLS_("\n"))
        
              
        if (temp2 != sTargetPath) {
        setCell(row, outlink, sTargetPath)
      }
        
    }



I know the linkset doesnt store the attributes I want, so I am assuming I need to open the linked module and get the attribute for that id and close it?



 


SystemAdmin - Tue Apr 24 17:07:20 EDT 2012

Re: Get Attribute from Outlinked Module
Bob_Swan - Wed Apr 25 03:07:03 EDT 2012

Your 'assumption' is correct, the dxl needs to id the far module, open it, verify the target object actually exists/is not deleted, then extract the attribute you require. Also throw in any special handling (richtext/ole objects) you may need.

Look in the dxl examples, especially the 'Example of Trace Analysis' file for some pointers.

(Or get the 'Requirements Management Add on' that has a lot of the functionality you are looking for already.)

Re: Get Attribute from Outlinked Module
llandale - Wed Apr 25 12:01:41 EDT 2012

Bob_Swan - Wed Apr 25 03:07:03 EDT 2012
Your 'assumption' is correct, the dxl needs to id the far module, open it, verify the target object actually exists/is not deleted, then extract the attribute you require. Also throw in any special handling (richtext/ole objects) you may need.

Look in the dxl examples, especially the 'Example of Trace Analysis' file for some pointers.

(Or get the 'Requirements Management Add on' that has a lot of the functionality you are looking for already.)

For outlinks, you can see all "LinkRef"s which let you get a name of the target module, but you cannot see the target Object. Once you open the target module's, you can use a "Link" loop and then get the
  • Objec oTarget = target(lnk)
and get its values:
  • A1_Value = probeAttr_(oTarget, "Attr1")
  • A2_Value = probeAttr_(oTarget, "Attr2")
Note that "probeAttr_" gracefully handles the case when the attribute doesn't exist.

Look through the DXL manual for "LinkRef"; you will routinely need a "LinkRef" loop before your "Link" loop when dealing with outlinks.

-Louie

Re: Get Attribute from Outlinked Module
SystemAdmin - Wed Apr 25 12:29:10 EDT 2012

Hi,

Thanks for the replies. I tried something else and it worked, but Im not sure if its a foolproof solution. Please see below.
 

for o in m do {
    col = 0
        row ++    
    
   for l in o -> "*" do {
 
        string temp2 = sTargetPath
        sTargetPath = sTargetPath fullName(target l) 
        
        ModuleVersion targetVer = targetVersion(l)
        
        
        if(exists(module targetVer)){
        
        //      if (null data(targetVer)) 
        //      {     
        //              Module m2 = load(targetVer, false)
        //      }
        // Works without this condition, but I thought I had to load this module????
 
                targetObj = target l
                
                
                if (probeAttr_(targetObj,"Attr2") != "")
                {
                        s1 = targetObj."Attr2"
                }
                else
                {
                        s1 = ""
                }
                
                if (probeAttr_(targetObj,"Attr3") != "")
                {
                        s2 = targetObj."Attr3"
                }
                else
                {
                        s2 = ""
                }            
        
                if (targetObj != null)
                {
                        sTargetPath = sTargetPath (NLS_(" ")) identifier (targetObj) (NLS_(" ")) s1 (NLS_(" ")) s2 (NLS_("\n"))
                }
        
                if (temp2 != sTargetPath) 
                {
                        setCell(row, outlink, sTargetPath)
                }
   }
        
}

Re: Get Attribute from Outlinked Module
SystemAdmin - Wed Apr 25 12:48:29 EDT 2012

SystemAdmin - Wed Apr 25 12:29:10 EDT 2012

Hi,

Thanks for the replies. I tried something else and it worked, but Im not sure if its a foolproof solution. Please see below.
 

for o in m do {
    col = 0
        row ++    
    
   for l in o -> "*" do {
 
        string temp2 = sTargetPath
        sTargetPath = sTargetPath fullName(target l) 
        
        ModuleVersion targetVer = targetVersion(l)
        
        
        if(exists(module targetVer)){
        
        //      if (null data(targetVer)) 
        //      {     
        //              Module m2 = load(targetVer, false)
        //      }
        // Works without this condition, but I thought I had to load this module????
 
                targetObj = target l
                
                
                if (probeAttr_(targetObj,"Attr2") != "")
                {
                        s1 = targetObj."Attr2"
                }
                else
                {
                        s1 = ""
                }
                
                if (probeAttr_(targetObj,"Attr3") != "")
                {
                        s2 = targetObj."Attr3"
                }
                else
                {
                        s2 = ""
                }            
        
                if (targetObj != null)
                {
                        sTargetPath = sTargetPath (NLS_(" ")) identifier (targetObj) (NLS_(" ")) s1 (NLS_(" ")) s2 (NLS_("\n"))
                }
        
                if (temp2 != sTargetPath) 
                {
                        setCell(row, outlink, sTargetPath)
                }
   }
        
}

Update:

Nevermind it doesnt work without the commented out condition.

How do you close the loaded modules?

Re: Get Attribute from Outlinked Module
llandale - Wed Apr 25 13:58:50 EDT 2012

llandale - Wed Apr 25 12:01:41 EDT 2012
For outlinks, you can see all "LinkRef"s which let you get a name of the target module, but you cannot see the target Object. Once you open the target module's, you can use a "Link" loop and then get the

  • Objec oTarget = target(lnk)
and get its values:
  • A1_Value = probeAttr_(oTarget, "Attr1")
  • A2_Value = probeAttr_(oTarget, "Attr2")
Note that "probeAttr_" gracefully handles the case when the attribute doesn't exist.

Look through the DXL manual for "LinkRef"; you will routinely need a "LinkRef" loop before your "Link" loop when dealing with outlinks.

-Louie

.. oops .. "for in-links"

Re: Get Attribute from Outlinked Module
llandale - Wed Apr 25 14:15:09 EDT 2012

SystemAdmin - Wed Apr 25 12:29:10 EDT 2012

Hi,

Thanks for the replies. I tried something else and it worked, but Im not sure if its a foolproof solution. Please see below.
 

for o in m do {
    col = 0
        row ++    
    
   for l in o -> "*" do {
 
        string temp2 = sTargetPath
        sTargetPath = sTargetPath fullName(target l) 
        
        ModuleVersion targetVer = targetVersion(l)
        
        
        if(exists(module targetVer)){
        
        //      if (null data(targetVer)) 
        //      {     
        //              Module m2 = load(targetVer, false)
        //      }
        // Works without this condition, but I thought I had to load this module????
 
                targetObj = target l
                
                
                if (probeAttr_(targetObj,"Attr2") != "")
                {
                        s1 = targetObj."Attr2"
                }
                else
                {
                        s1 = ""
                }
                
                if (probeAttr_(targetObj,"Attr3") != "")
                {
                        s2 = targetObj."Attr3"
                }
                else
                {
                        s2 = ""
                }            
        
                if (targetObj != null)
                {
                        sTargetPath = sTargetPath (NLS_(" ")) identifier (targetObj) (NLS_(" ")) s1 (NLS_(" ")) s2 (NLS_("\n"))
                }
        
                if (temp2 != sTargetPath) 
                {
                        setCell(row, outlink, sTargetPath)
                }
   }
        
}

If the other module is already loaded then the code will work. Note that it can be loaded invisibly; look at "Tools menu >Manage Open Modules...".

Its difficult to manage the "other" modules you've opened invisibly due to links, most folks just leave them open and don't worry about it.

Your "sTargetPath" stuff looks wrong as you keep appending paths and identifiers to the same string; so 3 links will result in a huge string.

Your "setCell" algorithm doesn't look right; the 10th object in the module will result in "row" being 10. If you only want to check table cells in your module, you can do this:

for o in m do
{  if (!table(o)) continue    // Ignore all objects except "table" header objects
   row = -1
   for oRow in oTable do
   {  row++
      cell = -1
      for oCell in oRow do
      {  cell++
         set(row, cell, whatever)
      }
   }
}
// or forget about "row" and "cell", just set values for "oCell" directly
// oCell.NameAttr = pathInfo


You can change this:

 

if (probeAttr_(targetObj,"Attr2") != "")
{
    s1 = targetObj."Attr2"
}
else
{
        s1 = ""
}


To just this:

 

 

  • s1 = probeAttr_(targetObj,"Attr2")


Someone needs to explain why "NLS" is needed; I doubt a single space is different in the different locality languages.

-Louie

 

Re: Get Attribute from Outlinked Module
SystemAdmin - Wed Apr 25 15:38:08 EDT 2012

llandale - Wed Apr 25 14:15:09 EDT 2012

If the other module is already loaded then the code will work. Note that it can be loaded invisibly; look at "Tools menu >Manage Open Modules...".

Its difficult to manage the "other" modules you've opened invisibly due to links, most folks just leave them open and don't worry about it.

Your "sTargetPath" stuff looks wrong as you keep appending paths and identifiers to the same string; so 3 links will result in a huge string.

Your "setCell" algorithm doesn't look right; the 10th object in the module will result in "row" being 10. If you only want to check table cells in your module, you can do this:

for o in m do
{  if (!table(o)) continue    // Ignore all objects except "table" header objects
   row = -1
   for oRow in oTable do
   {  row++
      cell = -1
      for oCell in oRow do
      {  cell++
         set(row, cell, whatever)
      }
   }
}
// or forget about "row" and "cell", just set values for "oCell" directly
// oCell.NameAttr = pathInfo


You can change this:

 

if (probeAttr_(targetObj,"Attr2") != "")
{
    s1 = targetObj."Attr2"
}
else
{
        s1 = ""
}


To just this:

 

 

  • s1 = probeAttr_(targetObj,"Attr2")


Someone needs to explain why "NLS" is needed; I doubt a single space is different in the different locality languages.

-Louie

 

Hi Louie,
Thanks again for the help.
sTargetPath is what I want, so that huge string will be set into one cell in excel for that particular object.

SuRS.SMC.33 "/Dubai/Requirements/SyRS SyRS.707 Technical Requirement Not Safety
/SelTrac MB 1.04/Requirements/SuRS SMC 60 Information Not Safety
" "/Sao Paulo L17/Requirements/SuRS SMC
"

Re: Get Attribute from Outlinked Module
SystemAdmin - Wed Apr 25 15:44:32 EDT 2012

llandale - Wed Apr 25 14:15:09 EDT 2012

If the other module is already loaded then the code will work. Note that it can be loaded invisibly; look at "Tools menu >Manage Open Modules...".

Its difficult to manage the "other" modules you've opened invisibly due to links, most folks just leave them open and don't worry about it.

Your "sTargetPath" stuff looks wrong as you keep appending paths and identifiers to the same string; so 3 links will result in a huge string.

Your "setCell" algorithm doesn't look right; the 10th object in the module will result in "row" being 10. If you only want to check table cells in your module, you can do this:

for o in m do
{  if (!table(o)) continue    // Ignore all objects except "table" header objects
   row = -1
   for oRow in oTable do
   {  row++
      cell = -1
      for oCell in oRow do
      {  cell++
         set(row, cell, whatever)
      }
   }
}
// or forget about "row" and "cell", just set values for "oCell" directly
// oCell.NameAttr = pathInfo


You can change this:

 

if (probeAttr_(targetObj,"Attr2") != "")
{
    s1 = targetObj."Attr2"
}
else
{
        s1 = ""
}


To just this:

 

 

  • s1 = probeAttr_(targetObj,"Attr2")


Someone needs to explain why "NLS" is needed; I doubt a single space is different in the different locality languages.

-Louie

 

Opps lets try this again.

Hi Louie,

Thanks again for the help.
  • sTargetPath is what I want, so that huge string will be set into one cell in excel for that particular object.

PM1.1 /PATH/MODULENAME1 ID ATTRIBUTE 1 ATTRIBUTE 2
/PATH/MODULENAME2 ID ATTRIBUTE 1 ATTRIBUTE 2
/PATH/MODULENAME3 ID ATTRIBUTE 1 ATTRIBUTE 2
/PATH/MODULENAMEn ID ATTRIBUTE 1 ATTRIBUTE 2
PM1.2 /PATH/MODULENAME1 ID ATTRIBUTE 1 ATTRIBUTE 2
/PATH/MODULENAMEn ID ATTRIBUTE 1 ATTRIBUTE 2

etc.
  • Setcell is straight from the ExporttoExcel.dxl so seems to work as intended.

  • I changed the probeattr as suggested, thanks!

  • Was your original response for "inlinks" ?