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

Get JSON data from URL into field form via button

Community Beginner ,
Jan 06, 2023 Jan 06, 2023

Copy link to clipboard

Copied

Hello,
I have seen similar topics but none seem to fit to my case. So I would like to fetch a JSON array from a web application in our local network once a button gets triggered by a user. Then the JS should write a value from that JSON array into a field on the PDF. Unfortunately it does not work. I have tested the code inside VSCode and it works fine there... What am I missing? Any help appreciated.

app.beginPriv();

fetch("http://domainXYZ/ajax/server_processing.php")
.then(response => response.json())
.then(data => {

const theData = data[0];

var dataConv = eval("(" + theData[0] + ")");

var FName = dataConv.Firstname;
});

this.getField('1').value = FName;

app.endPriv();

TOPICS
Create PDFs , JavaScript , PDF forms

Views

556

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jan 06, 2023 Jan 06, 2023

There is no "fetch" function in the Acrobat JavaScript model.  

However, there is an "HTTP.Net" object that can be used to perform HTTP operations.

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#net-http

 

It cannot be used from a document script. The only internet access from within an untrusted document context is the form submit.  

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#submitform

 

It's always helpful to look at the ac

...

Votes

Translate

Translate
Community Expert ,
Jan 06, 2023 Jan 06, 2023

Copy link to clipboard

Copied

Check the Javascript console for errors.

Votes

Translate

Translate

Report

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
LEGEND ,
Jan 06, 2023 Jan 06, 2023

Copy link to clipboard

Copied

I'm not at all convinced you can use the Promise API in Acrobat. Have you just lifted this code from browser JavaScript? Adobe Acrobat Javascript Promises - Stack Overflow

Votes

Translate

Translate

Report

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 06, 2023 Jan 06, 2023

Copy link to clipboard

Copied

LATEST

There is no "fetch" function in the Acrobat JavaScript model.  

However, there is an "HTTP.Net" object that can be used to perform HTTP operations.

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#net-http

 

It cannot be used from a document script. The only internet access from within an untrusted document context is the form submit.  

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#submitform

 

It's always helpful to look at the actual documentation.

 

 

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

Votes

Translate

Translate

Report

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