These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

importTextData()

krm240
Registered: Apr 17 2009
Posts: 95

I have a simple text doc with 1 column of data, multiple rows
I wish to import this into a drop down
At the moment, I am just trying to read the text file and populate 1 text field with any one row of data

The text field's name is Main.Pg1.zProjectID
Do I need to have this full name in the Txt data file? or just zProjectID????

The Trusted function executes, but does not update the field?

The import button script is as follows:
var myFPathName = "/c/temp/myData.txt";
var myRow = "0";
console.println("myFPath. " + myFPathName );
myImportProjects2(event.target, myFPathName, myRow); // call the priv function

The Trusted Function is as follows:
var myImportProjects = app.trustedFunction(function(oDoc,cPath,cRow)
{
app.beginPriv();
try
{
console.println("Data Import.");
oDoc.importTextData(cPath, cRow);
app.alert("Text Imported:\n" + cPath);
}
catch(e)
{
app.alert("Error During import of Project Text Data.\n" + e);
console.println("Error Text Data Import.\n" + e);
}
app.endPriv();
});

And my text file looks like this
"Main.Pg1.zProjectID"
"12"
"103"

Can anyone shed some suggestions as to what I am doing wrong?

My Product Information:
LiveCycle Designer, Windows
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
A few things you can try:

1. Instead of passing a string for the row number("0"), pass a number (0).
2. Get the return value of the importTextData method and let us know what it is.
3. If your catch clause is getting triggered, examine the other properties of the error object to give you more clues.
krm240
Registered: Apr 17 2009
Posts: 95
Suggested to:
1. Instead of passing a string for the row number("0"), pass a number (0).
Tried that, no change in results

2. Get the return value of the importTextData method and let us know what it is.
Tried that, received -2 Warning: User Cancelled Row Select
No clue whatthis means

3. If your catch clause is getting triggered, examine the other properties of the error object to give you more clues.
No catch clause being executed. No errors reported in console. The Try section completes normally
krm240
Registered: Apr 17 2009
Posts: 95
Does anyone have a sample of the function oDoc.importTextData(cPath, cRow);
that they can share with me that works.
I would like to see the format of their txt file, and the code to see what I am doing wrong.

I am still unable to get this working properly
At the moment, I just would like to import anyone row of data into a text field.
The larger goal is to populate a drop down list

Any suggestions would be greatly appreciated.
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
Another thing to try is to leave out the path and row number, and it will prompt you to select a file and row manually. If that works, you'll at least know your file is constructed properly. Also, try a different file location, such as the current user's documents folder.
krm240
Registered: Apr 17 2009
Posts: 95
Great idea
Did not think of that test. Tried it, the data files open and all looks good, able to see the data and select the row.

But does not put the value into the field. More testing ongoing!
krm240
Registered: Apr 17 2009
Posts: 95
As suggested - using the event.target.importTextData(); without parameters to test
Now I am getting an error 3 which is "Error: Invalid Row"

So my structure of my test txt file must be wrong.
The structure is as follows:
"zProjectID"
12
103
222

I have tried my Header line in "" and no quotes
I have tried my data in "" and no quotes
Tried no EOL characters and ";" as EOL for each row
I have tried the sample data in the example within the js_api_reference.pdf
Nothing works....

Questions:
Do I need anything to flag EOL for each row? if so, what do I use?
Does anyone see what I am doing wrong?
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
I didn't realize until now that you are doing this with a Designer form. It tried your exact file (without any quotes in header row or data rows) that I created in Notepad, and it worked just fine with an Acrobat created form. I wonder if you need to supply a fully qualified field name...
krm240
Registered: Apr 17 2009
Posts: 95
Per Thom
"importTextData will not work at all in an XFA PDF."
So now looking at using importDataObject ...