Skip to main content
Inspiring
April 19, 2024
Question

Implementing a Button to Check for Latest Form Version

  • April 19, 2024
  • 2 replies
  • 983 views

Hi everyone,
I'm trying to generate a button in my form to allow users to check if they downloaded the latest version online by implementing the code below. For some reason, it doesn't work. I defined the URL of the server where the latest form version is hosted and the latest file name allocated, but it still doesn't run. Any idea why?
----------------------------
var versionCheckUrl = "https://example.com/checkformversion";var xhr = new XMLHttpRequest();
xhr.open("GET", versionCheckUrl, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var latestVersion = xhr.responseText;

var currentVersion = this.getField("versionField").value;

if (latestVersion === currentVersion) {
app.alert("You have the latest version of the form.");
} else {
app.alert("A newer version of the form is available. Please download it from our website.");
}
}
};
xhr.send();

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
April 19, 2024

To start, besides the bad formatting, this is not Acrobat JavaScript. If you had looked in the console window you would have seen an error reported on the first line. Something like this;

ReferenceError: XMLHttpRequest is not defined

 

Where did you get this code? 

See the Acrobat JavaScript reference for a list of actual objects and functions in the Acrobat JavaScript model.

 https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
KaxkulAuthor
Inspiring
April 19, 2024

Thanks @Thom Parker, to this stage my knowedge is limited 😞

I didn't know it was that complicated. I had a problem where users download old versions and they don't check back for updates. I'm struggling with this, so I thought if something could check the name of the file with the version and alert users, that would be great. The code from a friend.

Thom Parker
Community Expert
Community Expert
April 20, 2024

There is a way to do this. And it's not that complicated. 

Use the doc.submitForm() function. You're server side script will need to be modified to return a data format that is acceptable to Acrobat, such as XML, XFDF, or FDF.

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
April 19, 2024

Check the JavaScript console (ctrl-j) for errors.

KaxkulAuthor
Inspiring
April 19, 2024

Thanks @Bernd Alheit I couldn't figure out the issue. Is there easier way to apply so far. As I may over complicating the solution.