Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Concatenate fixed text with datafields under certain conditions

Avatar

Not applicable
Hi,<br /><br />I need to concatenate fixed text with different (occurrences of) datafields into one fluent text. <br />All the data can be found in one XML but under several paths. There are also fields of 1..n datasets from which I want to concatenate fields under certain conditions. <br />In order to build this text, I also need to know before the loop, how many records I have in de 1..n dataset.<br /><br />The datastructure is as follows (L = Level T = Table):<br /><br /><L1-T1> - 1..1<L2-T1> - 0..1<L3-T1> - 1..n<L4-T1><br /> - 1..n<L3-T2> - 0..1<L4-T2> - 1..n<L5-T1><br /><br />I need data from <L3-T1>, selection of <L4-T1>, each <L4-T2> and a selection of <L5-T1>.<br /><br />Can anybody help me sort this problem?<br /><br />Many thanks in advance,<br /><br />Gert
0 Replies

Avatar

Level 10
Are you intending to do this at load time or is this an interactive exercise? Does each one of the nodes in the XML have a corresponding field on the form?

Avatar

Not applicable
This is intended to use at load time and the fields are nowhere else on the form. I want to compose letters for different clients.

Avatar

Level 10
So your data file would have multiple letters (of the same format) for different clients and you want to produce multiple letters with the same data merge operation ....right?



If so is the data structure for each letter the same ....for example the salutation is the same but the name changes (Dear Paul, or Dear Jean W. Smith .....).

Avatar

Not applicable
Yes,



Data structure, the fixed text and conditions are the same for all clients, only the data in the DB is different.

Avatar

Level 10
Then I suggest creatinng a template that represents the letter. Where varaiable data is supposed to go you can use a floating field. The floating can exist within a clock of text and you can bind an inbound data value to that field. Once the data is merged the field becomes text and the block is flowed again so that any additional spacings around the field are removed.



To add a floating field put the cursor in the text block location where you want the field to be. Under the Insert Menu choose Floating Field. The field is represented in the text block with a {TextField1}. A new entry is made in the hierarchy view. To set properties for the field highlight the object in the hierarchy view and the object palette (which also has the binding) will become active. Simply bind the field to the node in your XML and when you merge the template and data together it will take care of substituting the data into the field for you.

Avatar

Not applicable
I'm already using it that way, but it doesn't work if you want to create fluent text with more than one occurence of the same field.

For example if you want to list it like this:

<<L5-T1>Var[0]>, <<L5-T1>Var[1]>, <<L5-T1>Var[2]> and <<L5-T1>Var[3]>...

without knowing how many occurrences there will be.

I can list up more occurrences of one variable but it is always listed one after another as in a table, instead of next to eachother as in a fluent text. In addition, I also need to be able to add text between the different variables.

Avatar

Level 10
That makes it a lot more complicated ..... maybe it makes more sense to simply load the data into the data dom and write script to bind the information yourself. You could add multiple fields together and concatinate nodes as much as you want before setting the value of the fields.



Or you coudl manipulate the data using XSLT before you bind the data to the foem. In either case there is code to write.

Avatar

Not applicable
Could you give me a hint how the script should look like?

Avatar

Level 10
To get access to the data dom yopu would use the notation xfa.datasets.data. To get a feel for manipulating the Dom I suggest putting a large (lemgth and width) field on the form (this is temporary and only for debugging - once you figure out what to do you can delete the field). Make sure that it is visible and multi-line is set on. Now add a button - on the button click event do this command:



FieldName.rawValue = xfa.datasets.data.saveXML("pretty");



This will dump the data dom into the field so you can see the structure of it (the pretty flag is used to format the result into a nicer format for reading). Now that you see the structure you can access individual nodes in the xml by navigating to it. So you expressions look something like this:



xfa.datasets.data.form1.addressInfo.streetName.value



Note that to get the actual contents of the node the value property is used ....not the rawValue like in a field (this trips everyone up).



You can use methods like nodes to return back all nodes below a certain node. Once I have the nodes in an object I can get a length and loop through the different nodes to perform the operations that I want.



That should be enough to get you started.



Let me know how it turns out.

Avatar

Not applicable
I can see the datastructure with FieldName.rawValue = xfa.datasets.data.saveXML("pretty"); but I can't insert data in a field with the xfa.datasets.data code.

When I code this line, form1 isn't an option and I don't know what to choose (options are: all - applyXSL - assignNode - classAll - classIndex - className - getAttribute - getElement - id - index - isContainer - isNull - isPropertySpecified - loadXML - model - name - nodes - ns - oneOfChild - parent - resolveNode - resolveNodes - saveFilteredXML - saveXML - setAttribute - setElement - somExpression). What is the form1 in your example? I don't see a link to my data. Everything I tried (subform-name, DataConnection, the dataset...) wasn't working...

Do I have to do something else with the data first to be able to use it?



Gert

Avatar

Level 10
The form1.addressInfo.streetName.value was my attempt to show a structure in the data where form1 was the root node of the data that is being shown. You will not get object assist beyond the datasets.data node because it has no idea what the structure of your data is. So just to be clear is your data that is displayed in the fielname is:



10
Main Street
AnyCity
AnyState
AnyCountry



And you wanted the state value then you would use:

field1.rawValue = xfa.datasets.data.root.address.State.value

and it would return AnyState.

You could add values togther like this:

field1.rawValue = xfa.datasets.data.root.address.HouseNumber.value + " " + xfa.datasets.data.root.address.Street.value;

Hope that helps