Expand my Community achievements bar.

xfa.host.importData()

Avatar

Former Community Member

Hi,

I have stand-alone form PDF file, reader-extended, I open it with Reader-X,

and I have a piece of javascript behind a button on the form that calls the importData() method,

to import a XML data file.

say, my form has 6 fields: a, b, c, x, y, z

and the XML file has data in a, b, c, d, e, f

it appears that after the importData() call, my form fields a, b, c got populated with data from the XML file,

but the fields x, y, z got wiped out at the same time.  they become "null".

Is it supposed to work like that?

or maybe I have done something wrong?

If it's supposed to work that way, is there a way to keep the data in x, y, z after the importData() call?

is there another method that I can use to keep the original data in x, y, z?

thanks

13 Replies

Avatar

Level 10

Hi,

If you open the form in LC Designer and select x, y, and z fields. Go to the Object > Binding palette and select the binding as None. This means that the fields will not take part in an XML data import OR export. This might suit your requirements, depending on how you are processing returning data.

If you need to export data in the x, y, and z fields, then change the binding back to Normal/Name.

As a workaround, you could script variables to have the values of the x, y and z fields BEFORE the import script. Then repopulate the fields after import. Something like this:

// declare the variables

var myX = TextField1.rawValue;

var myY = TextField2.rawValue;

var myZ = TextField3.rawValue;

// import the xml

xfa.host.importData();

// repopulate fields

TextField1.rawValue = myX;

TextField2.rawValue = myY;

TextField3.rawValue = myZ;

Hope that helps,

Niall

Assure Dynamics

Avatar

Former Community Member

Hi, I tried both of your suggestions, but couldn't get either of them to work.

after I saved the field values to local variable, called importData(),

then it just stopped.

it never continued onto to the "repopulate fields" portion of the script.

what have I done wrong?

thanks

btw, are there "global variables" in the Designer?

if I can create some global variables, maybe I can restore my field values somehow?

Avatar

Level 10

Hi,

I think that I have given you a bad steer - sorry.

As part of the importData there is a remerge, which wipes out any script changes. So saving the rawValue to script variables or global variables will not work (afaik).

John Brinkman has a couple of posts, one in particular: http://blogs.adobe.com/formfeed/2008/10/data_binding_with_predicates.html. I tried to implement a solution based on predicate binding expressions but was unsuccessful.

I think that once an object has a binding, the importData operation will affect that object - its all or nothing.

Maybe someone with a better understanding of the XML/nodes structure can help.

Good luck,

Niall

Assure Dynamics

Avatar

Level 4

Niall,

Could you please look at the Field Presence Difficulty thread just a few posts below?  It won't take you long,   but is frustrating the heck out of me.  Thank you.

Avatar

Former Community Member

Thanks for the response.  Maybe I should re-state my question:

the XML data file was Exported from another PDF form (say, file "Y")  that has fields a, b, c, d, e, f.

so, what I really want is to find a way to get the field values in fields  a, b and c  of form "Y"

and put the values into another PDF form "X" that has fields a, b, c, x, y, z

while keeping the field values in  x, y, z  of the form "X" intact.

If importData() method can't do the job, is there any other way?

anything as long as it works would be fine.

thanks.

Avatar

Former Community Member

If you import a data file but only use some of the nodes in the xml then the extras will be caried through. When you import you are taking all of that data and its structure and you are creating a data dom. The binding on the fields will determine whether the field is included or not. You can have 1 of 4 options when binding:

1. Normal binding will simply use the structure of th ehierarchy in the form.

2. None - th efield will be excluded from the data file

3. Global - the field will shar eits value with all other liked named fields.

4. A binding expression where the field is bound to a predetermined structure (like a schema)

Note that binding is not dynamic .....that is to say that once it has been set at form load it cannot be changed.

So in your case I woudl suggest that you create a schema or sample xml file with all fields that you want in it and make sure that both forms follow that same structure.

Make sense?

Paul

Avatar

Former Community Member

Paul,   thanks for the response.

I must have done something wrong, but it's not working for me still, and this time it has a new behavior.

This time, I added a Schema Data Connection as you suggested to both PDF forms.  Same XSD file.

as the first try, I only have 1 field in the XSD, field "a".

and I bind the form field "a" with the one in the XSD, for both PDF forms.

The exported XML file looked great, it only has the field "a" node.

When I tried to Import this XML to the form,

the field "a" did contain correct data.

However, the processing stopped immediately after the importData() call.

This was the same as before.

But before, I used a "calculate" event in another field (hidden),

and I could then manipulate the data in field "a" after the Import.

This time however, the "calculate" event did not get fired.

So, now the question is,

how do I manipulate the field data immediately after the Import?

thanks.

Avatar

Former Community Member

I am sorry, it's my mistake.

I found out why the "calculate" event didn't fire, and fixed it.

Unfortunately, I now get the same problem as before.

Right after the importData() call, field values on other fields got overwritten,

I had an Integer field with a value 3, after the Import, it became the default value "0".

I need it to keep its value 3.  Otherwise my scripts won't work...

is there any way to do this?  please help!!

Avatar

Former Community Member

so if I understand you correctly, you have values in specific fields , then you do an import after those specific fields have been filled in and that is when you loose the values in your specific fields?

If that is the case then what is happening is that the import is overwriting the current DOM that has all of your current Data. After the import thebindings are executed and becuase there are no nodes for those fields they are getting wiped out. You can try changing the binding to none for those fields and that will no longer keep their values in the Dom...but this also means that the data for those fields will not be submitted either.

Make sense?

Paul

Avatar

Former Community Member

Yes.

But all the fields have their binding set as "None" except field "a",  their values still got wiped out after the importData.

Is this supposed to happen? or I have done something wrong?

do you see this happen to your forms?

I am not worried about Submit, these are just stand-alone PDF files, I don't submit them to anywhere.

thanks

Avatar

Former Community Member

I have not done what you have done .....normally you importdata to start the form not at some point while filling the form.I am surprised that those fields are getting wiped out. I think we will have to come up with a different strategy ...can you send the form and the data file to my email address and I will see if I can come up with a different approach. the email address is LiveCycle8@gmail,com  please include a brief description of the issue.

Paul