tags:

views:

682

answers:

2

I am trying to figure out how to make a hyperlink in a Livecycle Form which points to a URL which will change on different days that the form is rendered. For example on one day I might want the hyperlink to point to:

mywebsite/mypage?option=XXX

and on another day I want it to point to:

mywebsite/mypage?option=YYY

The XXX and YYY can be passed into the form's data pretty easily as XML, but I just don't know how to make it so that the hyperlink is changed to correspond to this.

Any suggestions?

A: 

Ended up using a 3rd party component to manipulate the PDF's hyperlinks...wish there was a better solution as this one costs about $1000.

Mike Gates
+1  A: 

This can be accomplished with JavaScript in LiveCycle Designer. The following script, placed on the Form's docReady event will let you dynamically change the URL of a text object.

 form1::docReady - (JavaScript, client)
// If this code is running on the server, you don't want it to run any code 
// that might force a relayout, or you could get stuck in an infinite loop
if (xfa.host.name != "XFAPresentationAgent") {

    // You would load the URL that you want into this variable, based on 
    // whatever XML data is being passed into your form
    var sURL = "www.stackoverflow.com"; // mywebsite/mypage?option=xxx

    // URLs are encoded in XHTML.  In order to change the URL, you need 
    // to create the right XHTML string and push it into the Text object's 
    // <value> node. This is a super simple XHTML shell for this purpose.  
    // You could add all sorts of markup to make your hyperlink look pretty
    var sRichText = "<body><p><a href=\"" + sURL + "\">Foo</a></p></body>";

    // Assuming you have a text object called "Text1" on the form, this 
    // call will push the rich text into the node.  Note that this call        
    // will force a re-layout of the form
    this.resolveNode("Text1").value.exData.loadXML(sRichText, false, true);
}

There are a couple of caveats: URLs in Acrobat are only supported in Acrobat 9.0 and later. So if someone using an older version of Acrobat opens your form, the URLs won't work.

Also, as you can see from the "if (xfa.host.name !=...)" line, this code won't run properly if the form is being generated on the server, because forcing a re-layout of a form during docReady can cause problems on certain older versions of the LiveCycle server. If you do need to run this script on the server, you should probably pick a different event then form::docReady.