Basically Identical Scripts but Part of One Won't Work

Explorer ,
Dec 06, 2019

Copy link to clipboard

Copied

Hi again, everyone.

 

So, I've got two folder level scripts that are practically identical. The only difference is that one is meant to merely save the current PDF Form open to specific folder based on field data, the other is meant to batch import from a tab deliminated file and save it based on the same criteria. 

 

PasteBin of Save Script - https://pastebin.com/NdWSzKxL

PasteBin of Import Script - https://pastebin.com/Wv0JG52p

 

The import script is the one not working, but only part of it isn't. The import is done with a while loop with a switch block inside of it. The first 4 cases in the switch are run if the last character of the string is a non-number (with NaN) and the -1 case is run if the string ends in a number.

 

It runs the imports of the first four cases with ease, but for some reason it breaks if it's all numbers. Whereas my Save script runs everything just fine. The code was literally copy-pasted from the Save to the Import but for some reason it's breaking when inside the While loop.

 

Any ideas?

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

199

Likes

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

Basically Identical Scripts but Part of One Won't Work

Explorer ,
Dec 06, 2019

Copy link to clipboard

Copied

Hi again, everyone.

 

So, I've got two folder level scripts that are practically identical. The only difference is that one is meant to merely save the current PDF Form open to specific folder based on field data, the other is meant to batch import from a tab deliminated file and save it based on the same criteria. 

 

PasteBin of Save Script - https://pastebin.com/NdWSzKxL

PasteBin of Import Script - https://pastebin.com/Wv0JG52p

 

The import script is the one not working, but only part of it isn't. The import is done with a while loop with a switch block inside of it. The first 4 cases in the switch are run if the last character of the string is a non-number (with NaN) and the -1 case is run if the string ends in a number.

 

It runs the imports of the first four cases with ease, but for some reason it breaks if it's all numbers. Whereas my Save script runs everything just fine. The code was literally copy-pasted from the Save to the Import but for some reason it's breaking when inside the While loop.

 

Any ideas?

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

200

Likes

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
Dec 06, 2019 0
Adobe Community Professional ,
Dec 06, 2019

Copy link to clipboard

Copied

Any error message in the console?

Likes

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
Reply
Loading...
Dec 06, 2019 0
Explorer ,
Dec 07, 2019

Copy link to clipboard

Copied

It was giving me a basic "You cant read or write to this file because it's open or you don't have rights" error. I got the same from earlier versions when I was first getting into JS and it was typically my code not putting together the directory or pulling the string from a variable right (or the folders not existing, oops). But in my other script it works just fine. It's just when I put it in the while loop it does it not carry that -1 value for the switch block correctly. 

 

Idk if I'm missing something easy or if there's just some other method I need to employ to guarantee it does. Thanks for the quick reply.

 

 

Likes

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
Reply
Loading...
Dec 07, 2019 0
Adobe Community Professional ,
Dec 09, 2019

Copy link to clipboard

Copied

You should debug your code. With console.println( ) you can display values of variables.

Likes

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
Reply
Loading...
Dec 09, 2019 0
Adobe Community Professional ,
Dec 06, 2019

Copy link to clipboard

Copied

So first, just because one script works doesn't say anything about a script you've modified so drastically. We'd need to see the script say anything about it, as well as know what if any error messages are being reported. Can you please post the text for the script. 

Likes

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
Reply
Loading...
Dec 06, 2019 0
Adobe Community Professional ,
Dec 06, 2019

Copy link to clipboard

Copied

The scripts are on pastebin.com

Likes

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
Reply
Loading...
Dec 06, 2019 0
Adobe Community Professional ,
Dec 07, 2019

Copy link to clipboard

Copied

I saw them, and they are are not basically identical. 

Likes

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
Reply
Loading...
Dec 07, 2019 0
Explorer ,
Dec 07, 2019

Copy link to clipboard

Copied

Sorry, I meant that they are 75% identical or more, because the only difference is that one includes a while loop. For some reason only the -1 case is faling in the while loop while the other four cases work fine. In my SaveAs script, it all works fine, so Idk if I'm missing something. Thanks again for looking.

Likes

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
Reply
Loading...
Dec 07, 2019 0
Adobe Community Professional ,
Dec 07, 2019

Copy link to clipboard

Copied

You write: "the -1 case is faling"
What happens in this case?

Likes

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
Reply
Loading...
Dec 07, 2019 0
Adobe Community Professional ,
Dec 07, 2019

Copy link to clipboard

Copied

You need to tell us if there are any messages in the Console Window. 

If you want help you have to provide specifics.

Likes

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
Reply
Loading...
Dec 07, 2019 0
Explorer ,
Dec 09, 2019

Copy link to clipboard

Copied


RaiseError: The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.
Doc.saveAs:225:Menu importAH:Exec
===> The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.

 

That is the only thing showing in the console. And I know it's that part of the code failing because it's only the strings without a letter at the end that can't be imported.

Likes

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
Reply
Loading...
Dec 09, 2019 0
Adobe Community Professional ,
Dec 10, 2019

Copy link to clipboard

Copied

I believe this error is mistaken, and in fact you have a security error. The doc.saveAs() function requires privilege. While this is a trusted function, I do not see anywhere in it the "app.beginPriv()" and "app.endPriv()" markers. These are required. 

You can read about how trused functions here: 

https://www.pdfscripting.com/public/Using-Trusted-Functions.cfm?sd=40

 

 

Likes

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
Reply
Loading...
Dec 10, 2019 0