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?

Mike Gates
  • 1,874
  • 3
  • 21
  • 40

3 Answers3

3

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.

1

I a number of complaints from users in WorkSpace that clicking links opened them in the same tab so they lost their WorkSpace form, and there's no option to change that in Designer 11. I think the solution I came up with for that would work for you too.

I made buttons with no border and no background, and in their click event have this line (in Javascript, run at client)

app.launchURL("http:/stackoverflow.com/", true);

It would be easy to add some logic to choose the right URL based on the day and it doesn't cause any form re-rendering.

In some spots where the hyperlink is in line with other text, I leave the text of the link blue and underlined but with no hyperlink, and just place the button (no background, no border, no caption) over it. Does require positioned and not flowed subforms for that to work, so depending on your layout it could get a little clunky.

Wow, just realized I am super late to the party. Well, for anyone using ES4 facing a similar problem . . .

Stephanie
  • 151
  • 8
0

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,874
  • 3
  • 21
  • 40