Expand my Community achievements bar.

SOLVED

How to reference data from the data binding in Javascript?

Avatar

Former Community Member

Hello,

I have a specific question -

I have a PDF template that I am designing in Livecycle Designer ES2. The data binding is XML Schema. For one of the fields I need to bind the data with some formatting.

For example: If my XML (based on the schema) is as follows

.

.

.

<xml:element name="EffectiveDT" value="2011/01/29"/>

<xml:element name="ExpirationDT" value="2012/01/29"/>

.

.

I want to bind a text filed named "Term" on the PDF Template to have value as <EffectiveDT> - <ExpirationDT>

I couldn't figure out how to bind this in the Binding Tab for the Text Field so I thought may be I can have a JavaScript that can let me assigne the concatenated value to this TextField and I can leave the binding blank.

Is it possible? What would be a correct solution for such use case? If we can go JavaScript way, could anyone please share a code snippet on how to access the data binding element from JavaScript?

Thanks in advance!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Is the Term field going to be used as a label, or is the user allowed to update it?  If it is just a label then you could use a Text object with two floating fields bound to the dates.

If you do want to use a TextField object, you could use some JavaScript like the following, in the initialise event;

 

this.rawValue = parent.dataNode.resolveNode("element[0].value").value + " - " + parent.dataNode.resolveNode("element[1].value").value;;

This code assumes that your xml looks like;

<xml:term>

  <xml:element name="EffectiveDT" value="2011/01/29"/>

  <xml:element name="ExpirationDT" value="2012/01/29"/>

</xml:term>

And that the the TextField object has a parent subform that is bound to the xml:term element (so the parent.dataNode resolves to xml:term).

Also, I've also found that it can cause problems to use element and attribute names that conflict with the XFA Object names.  I would normally have written the resolveNode argument used above something like;

parent.dataNode.resolveNode("element.(name=='EffectiveDt'].value").value

But because the XFA object representing element also has a name property I've never found a way of referring to the xml attribute called name in JavaScript.

So the tricky part will be if they can update the values and you then have to update your xml fields manually, not that the actually updating is hard it'll be the parsing of the new value that'll be tricky.

Hope this helps,

Bruce

View solution in original post

7 Replies

Avatar

Level 10

Hi,

I am not sure that you can combine two nodes on the fly and represent them in one field.

One workaround would be to have two hidden fields bound to the data and then in the calculate event of the hidden field have your concat script.

Niall

Avatar

Former Community Member

Thanks Niall.

Is there any other way? I may have many such fields on the template and it might be very hard to create hidden fields for all.

In general, can we reference Data Binding from Java Script or Form Cal at all?

Avatar

Correct answer by
Level 10

Hi,

Is the Term field going to be used as a label, or is the user allowed to update it?  If it is just a label then you could use a Text object with two floating fields bound to the dates.

If you do want to use a TextField object, you could use some JavaScript like the following, in the initialise event;

 

this.rawValue = parent.dataNode.resolveNode("element[0].value").value + " - " + parent.dataNode.resolveNode("element[1].value").value;;

This code assumes that your xml looks like;

<xml:term>

  <xml:element name="EffectiveDT" value="2011/01/29"/>

  <xml:element name="ExpirationDT" value="2012/01/29"/>

</xml:term>

And that the the TextField object has a parent subform that is bound to the xml:term element (so the parent.dataNode resolves to xml:term).

Also, I've also found that it can cause problems to use element and attribute names that conflict with the XFA Object names.  I would normally have written the resolveNode argument used above something like;

parent.dataNode.resolveNode("element.(name=='EffectiveDt'].value").value

But because the XFA object representing element also has a name property I've never found a way of referring to the xml attribute called name in JavaScript.

So the tricky part will be if they can update the values and you then have to update your xml fields manually, not that the actually updating is hard it'll be the parsing of the new value that'll be tricky.

Hope this helps,

Bruce

Avatar

Former Community Member

Thank you very much Bruce, that helped. The exact syntax did not work for me but I could get it working with the absolute path for the elements.

Thanks again!

Avatar

Level 2

Hello CODevGroup​,

what syntax did you use now? Where is the exact path for the element (the path of the data binding) inserted in the sample code of BR001? (with or without $)

My data binding path looks like this: $.ServiceRequest.copylastchangeddate_9WVLT0YP0XZ2GHZIFXHWYA21U

And the name of this Date/Time Field is: dtLastChangedDate

So do I need to write in the script editor for this field:

parent.dataNode.resolveNode("$.ServiceRequest.copylastchangeddate_9WVLT0YP0XZ2GHZIFXHWYA21U.value").value

or what I also read a lot:

xfa.record.$.ServiceRequest.copylastchangeddate_9WVLT0YP0XZ2GHZIFXHWYA21U

I have a similar requirement. I want to use the value of the field, what has a data bindung, and make some changes in the representation. Currently, I get the date in the following format: YYYYMMDDSSSS.12345. But I want the date to be displayed in the format: DD.MM.YYYY (without time). So I wrote the following script:

var dateString = parent.dataNode.resolveNode("$.ServiceRequest.copylastchangeddate_9WVLT0YP0XZ2GHZIFXHWYA21U.value").value;

var year = dateString.substr(0, 3);

var month = dateString.substr(4, 5);

var day = dateString.substr(6, 7);

var newDateString = day + "." + month + "." + year;

dtLastChangedDate.rawValue = newDateString;

Thanks very much for help in advance!

Best regards,

Deborah

Avatar

Level 10

Hi Deborah,

I think you need to change

var dateString = parent.dataNode.resolveNode("$.ServiceRequest.copylastchangeddate_9WVLT0YP0XZ2GHZIFXHWYA2 1U.value").value;

to

var dateString = pxfa.record.ServiceRequest.copylastchangeddate_9WVLT0YP0XZ2GHZIFXHWYA21U.value;

Regards

Bruce

Avatar

Level 2

Hi Bruce,

thanks so much for your help!!

It now works with: var dateString = xfa.record.ServiceRequest.copylastchangeddate_9WVLT0YP0XZ2GHZIFXHWYA21U.value;

Have a lovely day,

Best regards Deborah