How to properly place Hyperlinks in generated document using a custom script?

40 Views Asked by At

I'm trying to put an hyperlink in a generated document using a custom script, because the link needs to be fetched by the script.

I'm generating the XML in the custom script like follows:

(...)
var thegeneratedURL = "https://www.google.com"
var thelinktext = "test"
var xmlCommitID = xmlDOM.createElement("CommitID-Hyperlink");
var commitIdLink = xmlDOM.createElement("a");
commitIdLink.setAttribute("href", thegeneratedURL);
var commitIdText = xmlDOM.createTextNode(thelinktext);
commitIdLink.appendChild(commitIdText);
xmlCommitID.appendChild(commitIdLink);
xmlRow.appendChild(xmlCommitID);

return xmlDOM.xml; 

Then I'm calling the script in the respective fragment enter image description here

...and inserting the custom field

enter image description here

However, when I generate the document the link text is fine but the URL is not:

enter image description here

Anybody knows what I'm missing?

Thank you!!

2

There are 2 best solutions below

1
Geert Bellekens On BEST ANSWER

This is the code I use, to link directly to diagram url's on a html export of an EA-Model

function getRTFData(diagram, baseUrl)
    
    dim diagramUrl
    diagramUrl = getDiagramLink(diagram, baseUrl)
    
    dim xmlDOM 
    set  xmlDOM = CreateObject( "Microsoft.XMLDOM" )
    'set  xmlDOM = CreateObject( "MSXML2.DOMDocument.4.0" )
    xmlDOM.validateOnParse = false
    xmlDOM.async = false
     
    dim node 
    set node = xmlDOM.createProcessingInstruction( "xml", "version='1.0'")
    xmlDOM.appendChild node
'
    dim xmlRoot 
    set xmlRoot = xmlDOM.createElement( "EADATA" )
    xmlDOM.appendChild xmlRoot

    dim xmlDataSet
    set xmlDataSet = xmlDOM.createElement( "Dataset_0" )
    xmlRoot.appendChild xmlDataSet
     
    dim xmlData 
    set xmlData = xmlDOM.createElement( "Data" )
    xmlDataSet.appendChild xmlData
     
    dim xmlRow
    set xmlRow = xmlDOM.createElement( "Row" )
    xmlData.appendChild xmlRow
        
    dim formattedAttr 
    set formattedAttr = xmlDOM.createAttribute("formatted")
    formattedAttr.nodeValue="1"
    
    dim xmldiagramLink
    set xmldiagramLink = xmlDOM.createElement( "DiagramLink" )  

    xmldiagramLink.text = "<a href=""$inet://" & diagramUrl &"""><font color=""#0000ff""><u>" & diagram.Name & "</u></font></a>"
    xmldiagramLink.setAttributeNode(formattedAttr)
    xmlRow.appendChild xmldiagramLink
    
    getRTFData = xmlDOM.xml
end function

function getDiagramLink(diagram, baseUrl)
    dim link
    link = baseUrl & "/?guid="
    'get diagram GUID
    link = link & diagram.DiagramGUID
    'remove braces
    link = replace(link, "{","")
    link = replace(link, "}","")
    'return 
    getDiagramLink = link
end function

function getObjectDiagramLink(objectID, baseUrl)
    dim element
    set element = Repository.GetElementByID(objectID)
    'get diagram
    dim diagram 
    set diagram = getFirstDiagram(element)
    'get the xml data
    getObjectDiagramLink = getRTFData(diagram, baseUrl)
end function

function getFirstDiagram(diagramOwner)
    set getFirstDiagram = nothing 'initialize
    'get first diagram
    dim diagram as EA.Diagram
    for each diagram in diagramOwner.Diagrams
        set getFirstDiagram = diagram
        exit function
    next
end function

This code is used in a script fragment like this:

getObjectDiagramLink(#OBJECTID#, "https://urlToHTMLExport.com")

It generates a link like the following:

https://urlToHTMLExport.com/?guid=B79FA03B-33F3-46b7-8F97-3DDE8E653753

with the name of the diagram being displayed.

enter image description here

0
gfarkasd On

I would do it using the formatted="1" attribute and a simple html hyperlink as string (so I wouldn't bother assembly it with xml node objects). Documentation about formatted="1": https://sparxsystems.com/enterprise_architect_user_guide/14.0/model_publishing/example_output_of_an_rtf_templ.html (at the bottom, Notes section) Also, I'm not sure if "CommitID-Hyperlink"-"CommitID.Hyperlink" conversion works correctly, so I would try a field name without - or . characters - at first at least.

Farkas