Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

importDataObject

Avatar

Former Community Member

Hi all,

I have a form, that uses a button to add attachment to form with specific index. Now with reader 9 the functionality seems to be awkward.

Correct me if I am wrong, but If I use this code:

var myDoc = event.target;

myDoc.importDataObject("test");

a file should be added to the PDF form with index test. Now if I call the code one more time, I would expect the attachment to be replaced (worked with reader 8), however with reader 9, two attachments are present and only one has the "test" index.

Any ideas what to do with this? I want to avoid indexing based on number sequence.


Thanks

Jan

1 Accepted Solution

Avatar

Correct answer by
Level 10

call the following method before you add; let me know the response.

myDoc.removeDataObject("test");

Nith

View solution in original post

7 Replies

Avatar

Correct answer by
Level 10

call the following method before you add; let me know the response.

myDoc.removeDataObject("test");

Nith

Avatar

Former Community Member

Hi Nith,

that is what I did, I also added one more condition before this line to check whether attachment is present or not (based on hidden field).

I wanted to avoid user hitting cancel at the attachment dialog box and having the attachment removed. (I don't know how to catch cancel event on the system file dialog box)

Thanks a lot,

Jan

Avatar

Level 10

Var attResult = doc.importDataObject("yourObjName");

// attResult will be false if the user hits the cancel button; otherwise it will be true.

Hope this may help you to proceed.

Nith

Avatar

Level 2

Hi,

I tried to add the attachment in PDF form. I wanted to convert the attached file to xml file format while submitting the form. Please help me to resolve this issue

var sFile = "myFile";

myDoc.importDataObject({cName: sFile});

var myDataObject = myDoc.getDataObject(sFile);

var sFileName = myDoc.path;

Var item = myDoc.get

app.alert(myDataObject +"f" +sFileName );

Avatar

Level 10

Sorry, your script and description doesn't make much sense right now: Do you want to convert a whatever file into an XML during import? Why? What kind of file do you try to import and for what exactly?

Avatar

Level 2

Hi,

Thanks for your response!!

Tool: Adobe acrobat LiveCycle Designer ES 8.2

I’m creating PDF form. In that form, I have to attach the spreadsheet.  In submit click, have to convert all the data to XML format (including spreadsheet data). The converted XML data will insert to Database.

Searching the script for add the attachment in PDF form. I used below script and able got the filename alone. I want to get data which is present in spreadsheet and that will convert to XML format while submit click.

var myDoc = event.target;

var sFile = "myFile";

Var a=myDoc.importDataObject({cName: sFile});

var myDataObject = myDoc.getDataObject(a);

var sFileName = myDoc.path;

Please advise me urgently!!

Avatar

Level 10

You cannot convert a native XSL or XSLX file into an XML by JavaScript. Why don't you export the data from Excel spreadsheet directly as XML file and then import this XML into your form?

Anyway, I think you should first read some tutorials to get an idea of what is possible.

http://forms.stefcameron.com/2009/08/03/connecting-to-a-schema/

http://forms.stefcameron.com/2006/09/18/connecting-a-form-to-a-database/

LiveCycle Blog: XML per Skript in Adobe Reader importieren//Import XML via Script into Adobe Reader

Display an XML Spreadsheet