Copy link to clipboard
Copied
I have created folder level scripts with corresponding buttons to create unique file names each time based on information in the file and the users who saved the file to a specified location.
Ocassionally there are files that will go to the same location, but the file itself does not have the named fields in my script and instead of created a second set of buttons and script for these types of files I would like the script to be able to identify if the file has the named field to use one naming convention and if not use another.
I can't seem to find the correct syntax or functions to do this. Below is a sample script with my line of thinking to complete this.
//Create Filename
function Name(){
if (doesObjectExists("Original Accession")==true){
var myFileName = this.getField("Original Accession").value + " " + getLoginName() +" " + myDateString();
}
else{
var myFileName = myIdString() + " " + getLoginName() +" " + myDateString();
}}
Later in the script i have a save as comand to a location with " +myFileName+".pdf". I do understand these need to be trusted functions and I have that set in place the bug I am ecountering is that the script doesn't understand myFileName. If I get rid of the if/else statement i recognizes one or the other of the naming conventions.
Copy link to clipboard
Copied
What your current code is trying to do is basically this:
- If the field "Original Accession" doesn't exist, use its value in the new file name.
That doesn't make sense.
Copy link to clipboard
Copied
If this.getField("Original Accession") is null then the field doesn't exists.
Copy link to clipboard
Copied
It doesn't seem to work for me. I still get the same reference error of myFileName is not definted.
I wrote
function Name(){
if (this.getField("Original Accession")==null){
var myFileName = this.getField("Original Accession").value + " " + getLoginName() +" " + myDateString();
}
else{
var myFileName = myIdString() + " " + getLoginName() +" " + myDateString();
}}
is the problem that I need to definte myFileName outside the statement? Maybe something along the lines of
//Create Filename
var myFileName = function(){
if (this.getField("Original Accession")==null){
var Name = this.getField("Original Accession").value + " " + getLoginName() +" " + myDateString();
}
else{
var Name = myIdString() + " " + getLoginName() +" " + myDateString();
}}
Copy link to clipboard
Copied
Have a closer look at your code... This part has a clear issue with it:
if (this.getField("Original Accession")==null){
var Name = this.getField("Original Accession").value + " " + getLoginName() +" " + myDateString();
}
Copy link to clipboard
Copied
Please forgive me as my knowledge in coding is patchy at best. I am also constrained by using the Adobe Standard and not the Pro version so the debuging tool is hard for me to access and truly use. I am just unable to wrap my head around the problem to think of the solution.
If only use a single naming convention
var myFileName = this.getField("Original Accession").value + " " + getLoginName() +" " + myDateString(); where "Original Accession is a field in the file. the LoginName is the users windows username, and the Date String is a time stamp it works when i use the save as function
this.SaveAs("file path/"+ myFileName +".pdf")
When i try to make a statment that defines what myFileName depenedent if "Original Accession" fields exists or not i get the reference error if undefitend myFileName.
Copy link to clipboard
Copied
What your current code is trying to do is basically this:
- If the field "Original Accession" doesn't exist, use its value in the new file name.
That doesn't make sense.
Copy link to clipboard
Copied
Thank you so much. That was exactly my problem plus I needed to define that the variable myFileName existed outside that statement.
Thank you again for your help. my code now looks like this and it works as needed.
//Create Filename
var myFileName;
if (this.getField("Original Accession") != null){
var myFileName = this.getField("Original Accession").value + " " + getLoginName() +" " + myDateString();
}
else{
var myFileName = myIdString() + " " + getLoginName() +" " + myDateString();
}