Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Possible to fill form field from another filled with xml-data

Explorer ,
Jan 07, 2020 Jan 07, 2020

Hi.

 

Is it possible to fill in a text field an xml export and after that i can press a button "calculate"

an for example the button search a specified text from the xml export and fill it to the right form field?

 

sry, bad english, i hope you understand what i mean.

 

exp.

<Auftragsnummer_Fremdsystem>KKU00123456</Auftragsnummer_Fremdsystem>

 

so fill "KKU00123456" in an extra form field.

 

eMd

TOPICS
PDF forms
3.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Jan 08, 2020 Jan 08, 2020

Just took a look at the E4X reference and it seems to be easier then I thought.

 

Here is a script you can put on a button that will auto fill a form field from XML entered into a different field

 

var myXML = XML(this.getField("XMLField").value;

this.getField("OtherFormField").value = myXML..Auftragsnummer_Fremdsystem;

 

You'll need to change the form field names to match the ones on your form.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 07, 2020 Jan 07, 2020

HI, 

Can you confirm the version of the software and the operating system you are using?

I am not sure I fully understand your question but it looks like you will need to create a complex script to get the button to work. Another challenge will be to allow your pdf to connect to a specific external file, which is not always possible for other users.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 07, 2020 Jan 07, 2020

i use windows 10 enterprise ans adobe acrobat standard 2017.011.30142

 

and every user will get the xml data to the clipboard and can paaste it in their pdf file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 07, 2020 Jan 07, 2020

Yes, this is possible. There are a couple of different ways to do this.

1. If the XML tag matches a field name, and the XML uses a simple flat gramar, then importing the XML will automatically fill the field with the same tag name.

2. Use Acrobat JavaScript to open the XML file and parse out the data.

 

Depending on how you want to do this, Privilege may be required, meaning that there are certain operations that cannot be done in from within a PDF scripting context, such as silently opening an XML file from the user's file  system.

However, if the XML data is text in a form field, then there is no problem. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 07, 2020 Jan 07, 2020

But is it not possible that the button reads the content of the field and fills the corresponding values ​​in certain fields? It always has to work with an xml file?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 07, 2020 Jan 07, 2020

If the XML data is pasted into a field on the form, then it is very easy for a script to read the XML out of the field, parse it, and then fill another field with the results.  

 

Acrobat includes the deprecated E4X XML model. It's an easy way to parse XML.

https://en.wikipedia.org/wiki/ECMAScript_for_XML

 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 08, 2020 Jan 08, 2020

Thank you very much. Are there any examples I can use as a guide? Unfortunately I am not a programmer, but I would like to make the work for my 2 colleagues a little easier.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2020 Jan 08, 2020

You'll find tutorials on E4X here:

https://developer.mozilla.org/en-US/docs/Archive/Web/E4X/Processing_XML_with_E4X

 

However, if you are not a programmer then this may not help much. PM me if you are interested in hiring a developer. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2020 Jan 08, 2020

Just took a look at the E4X reference and it seems to be easier then I thought.

 

Here is a script you can put on a button that will auto fill a form field from XML entered into a different field

 

var myXML = XML(this.getField("XMLField").value;

this.getField("OtherFormField").value = myXML..Auftragsnummer_Fremdsystem;

 

You'll need to change the form field names to match the ones on your form.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 09, 2020 Jan 09, 2020

 

var myXML = XML(this.getField("Daten").value);

this.getField("AuftragsNrFremdsys").value = myXML.Auftragsnummer_Fremdsystem;

 

I tried the following code.

Unfortunately it does not work.

 

Thank you very much for your advice, I will read myself in the reference, maybe I will find the error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2020 Jan 09, 2020

You'll need to look in the console window to see if any errors are being reported.

In fact, the console window is where you want to testing out and developing this code. 

You'll find a tutorial here on how to use it:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

However, you missed a very important bit in the code I posted. There are two periods ".." separating the XML object form the tag reference. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 09, 2020 Jan 09, 2020

I corrected the error, but the console writes "Syntax error"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2020 Jan 09, 2020

Try running just the first line of code in the Console window. What you want to do is verify that the XML text from the form field is being parsed. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 09, 2020 Jan 09, 2020

ok, first line without problem.

 

I copied the rest of it, but my field remains empty. But I have no more errors in the console

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2020 Jan 09, 2020

Now, I want you to run two separate lines in the console and post the results here.

The first line is this

 

myXML..Auftragsnummer_Fremdsystem

 

If this returns nothing

Then run this line, it should print out the entire XML.

 

myXML

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 09, 2020 Jan 09, 2020

ok, so i understand how it works with troubleshooting.

myXML

brought no result in the console. Apparently the field is not parsed

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 10, 2020 Jan 10, 2020

What happens when you execute this line in the console

 

this.getField("Daten").value
Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 10, 2020 Jan 10, 2020

Sorry i learn now 🙂

 

this result is the text from the field

 

if i post this line in console

 

var myXML = XML(this.getField("Daten").value)

 

i get the following answer:

 

SyntaxError: invalid XML tag syntax
undefined

 

i played a litte more:

XML(this.getField("Daten").value)
Test123

i filled the text field Only with

<Ordnungsnummer>Test123</Ordnungsnummer>

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 10, 2020 Jan 10, 2020

Ok, so i know the Problem.

I can only parse one <></>

if there a more than one <a>a</a><b>b</b> i get an error...

 

so i cant parse a whole xml-data with lots more <></>...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 10, 2020 Jan 10, 2020

You must use the correct XML syntax like this:

<top><a>a</a><b>b</b></top>

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 10, 2020 Jan 10, 2020
LATEST

The XML object can parse huge blocks  of complex XML. The problem is not the function, the problem is the XML, it is incorrect. I would suggest you find the error in the XML code. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines