Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

JavaScript or FormCalc if XML element exists flag

Avatar

Level 2

In LiveCycle, how do I show something based on XML value? I recently switched from coding XSL to using LiveCycle for dynamic PDF document creation. In XSL, I would use a simple IF statement referring to the XML (a flag equal to 1) to determine if a particular part of a document should appear. For example:

<xsl:if test="formletter/flag = 1">

  <fo:block>This text would display</fo:block>

</xsl:if>

How would I do this in LiveCycle using JavaScript or FormCalc, or is there some other method without using a scripting language? Thank you.

1 Reply

Avatar

Level 2

I figured out how to do it using JavaScript within LiveCycle.  For those who need it, I will paste my solution.

You first need to make sure the text you want to show/hide is inside its own Text Object and you want to set it to Invisible.  In my example below, my Text Object is named "FlagText."  As you can see below, I have this text object inside a Subform named "sfPageText."  I am using Floating Fields for my XML flag and for my text that appears on the page because in my particular document, this text is not interactive.  Perhaps there is a better way to do this, but in my layout, I had to put my floating field flag inside its own Text Object, and I had to set the Text Object to Invisible.  The reason for this is because when you try to set just the Floating Field to Invisible, it still shows up in the PDF output.

Highlight your Floating Field flag in the hierarchy to enter this code, and put this code inside your JavaScript "initialize" section.  You will need to rename the items in this code to the same names that you used in your own hierarchy.

if (this.rawValue == "1") {

  formletter.Page1.sfPageText.FlagText.presence = "visible";

}