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 error message in the console?
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.
You should debug your code. With console.println( ) you can display values of variables.
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.
The scripts are on pastebin.com
I saw them, and they are are not basically identical.
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.
You write: "the -1 case is faling"
What happens in this case?
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.
===> 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.
You need to tell us if there are any messages in the Console Window.
If you want help you have to provide specifics.
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: