Expand my Community achievements bar.

Read data from external file

Avatar

Level 2

I just began to work with LiveCycle Designer recently. Before posting this question I did a search but could find what I am looking for.

A design a PDF with LC Designer and in the Javascript code I use some variables that change their value monthly. Is it possible that without changing the code I can read the new values from a external file? I guess that it should be possible to read from an XML file, but could not find how. I do not try to input data in a form from a external file: I will use inside my Javascript code.

I'll appreciate your help

8 Replies

Avatar

Former Community Member

Hi

I've attached an example of pdf template with 2 text fields and "import data" button.

On click event the  xfa.host.importData() function is launched then you can browse and select data file  (also attached) to  import into the template.

In addition you can import data using Forms>Manage Form Data>Import data option of the Acrobat/Reader.


Note that if you are using free reader you should Reader Extend the form using LiveCycle Reader Extensions in order to enable import data.

Yan.

Avatar

Level 2

Thanks for this sample, but it is not totally what I want:

  • Well, if it is called from a button, I'm able to call it automatically from an internal programming condition; no problem, but...
  • I tried to call a fixed filename, as xfa.host.importData("myfile.xml"); but there is an internal error saying that security configuration does not allow to access that method or property. How can I avoid this problem?
  • And second: you showed in this simple PDF that I can read form values from an external xml file, but, can I read Javascript-variable values instead?

There is other point I didn't understand well: when I run your PDF with Acrobat Reader, I have to push the button to retrieve the file with the data. However, if I run it with the Designer, I see automatically the data within the preview: how do you achieve that?

Sorry if these questions seem too simple, but I'm just a newbie with Designer

Avatar

Former Community Member

There is a security restriction that do not allow to hardcode the name of the data file.

User should be aware wich data he imports into the form.

If I'm not wrong you can register the importData as a trusted function and then you'll be able to do it,  so you should check how to create "trusted functions".

It is not so clear what do you mean by this sentence.

The last point:  you can set the name of the preview data file which will be loaded only when you preview it in the Designer, go to Form Properties>Preview tab.

Yan.

Avatar

Level 2

Ok, I see. I'll explain what I am doing

The form I created is a questionnaire: depending of the user answers it shows a result or other. The code changes dinamically in this simplified way:

var max = 60;

var min = 18;

if ( myAge.rawValue>max ) { myComment.rawValue = "You are over the maximum age"; }

else if ( myAge.rawValue<min )  {myComment.rawValue = "You are below the minimum age"; }

The user inputs in myAge and see the comments in myComment

What I want is to load those max and min values from an external file, because they change, let's say, weekly. If this change comes automatically without the user to load any file, it will be easier for him/her. Is this possible?

You mean that it is necessary to create a "trusted function": I read somewhere that it is possible if I certified the document, is it correct? Anyway, I could not find how to do it. Could you help me on that too?

Avatar

Former Community Member

Ok, now I  understand.


The first solution I can think about is that you can have a web service update your form with max and min values once the user opens the your form.

You can capture this values on invisible fields or global variables and use them in your validation script.

In order to consume a web service you have to create a new data connection to your web service wsdl file.

Regarding the trusted function I've never created one before but I know that you have a full documentation how to create it in JavaScript for Acrobat API Reference .

Yan.

Avatar

Level 2

Well, it seems too complicated for a newbie. First, I do not know what a web service is for the LC Designer. Could you point to a place where I can read a sample and learn from it.

Second, regarding the link you mentioned, if I manage to use the web service, do I still have to create a trusted function or a digitally signed PDF?

Avatar

Former Community Member

You can find here a good sample by Stefan Cameron of connecting to web service :http://forms.stefcameron.com/2007/05/21/connecting-to-a-web-service/

If you manage to implement your needs with webservice no need to use trusted function.

Yan.

Avatar

Level 2

In order to use webservice, you need adobe reader extensions to enable to form to make calls to webservice. Generally Adobe Free Reader does not support webservice calls.

If you form is everytime rendered with a xml file to populate some data, i suggest you to use two hidden text fields where you can set the values for these two at the form initialize method.

Once these two variables are set, you can make use of them globally in your form.