Copy link to clipboard
Copied
Good evening, I am trying to find a way to print the strings in my Javascript into the console log, that, or print the strings into a txt file.
Here is what I have so far:
var File = this.documentFileName.replace(/.pdf/,"");
var First = this.getField("First Name");
var Last = this.getField("Last Name");
var Middle = this.getField("Middle Initial");
var State = this.getField("State");
var Lab = "MDV";
if (State = "AL" && "CT" && "FL" && "GA" && "HI" && "IL" && "KY" && "LA" && "MD" && "DC" && "MI" && "MN" && "NJ" && "NM" && "NC" && "OR" && "SC" && "TX" && "UT" && "VA" && "WY") {
lab = "HELIX";
}
var Patient = Last + ", " + First + " " + Middle + " - " + Lab + " - " + State + " - " + "REC FORM";
I am looking for a way to print the variable, "File" so that we can see which files are not correctly spelled, and so that our checkers can correct the files later on.
Use this code:
console.println(File);
Copy link to clipboard
Copied
Use this code:
console.println(File);
Copy link to clipboard
Copied
PS. You have multiple errors in your code...
Copy link to clipboard
Copied
I've found that I do have quite a few errors. One of them is that, "this.documentFileName is undefined" in the console.
Do you mind if I ask, if there is a fix for this issue?
Copy link to clipboard
Copied
That's actually fine... However, it will only work if you have a document open at the time you run the code, of course.
Copy link to clipboard
Copied
I tested it as a batch action in Acrobat, and it seems to work, except for two parts of my code.
var Patient = Last + ", " + First + " " + Middle + " - " + Lab + " - " + State + " - " + "REC FORM";
When it prints to the console, it comes out looking like this:
[object Field], [object Field] [object Field] - MDV - WY - REC FORM
The state and lab are incorrect, and it doesn't seem to print out the names like it should, rather, [object field] comes up.
Thank you for your help and patience by the way.
Copy link to clipboard
Copied
You probably want the "value" of the field
try this:
var Patient = Last.value + ", " + First.value + " " + Middle.value + " - " + Lab + " - " + State.value + " - " + "REC FORM";
Copy link to clipboard
Copied
Awesome! It now all prints like it should, and the lab value changes in relation to the state!
I have hopefully one more problem however, when I run the program, it will change the customer's state to WY.
This is the code that I have so far:
if (State.value = "AL" && "CT" && "FL" && "GA" && "HI" && "IL" && "KY" && "LA" && "MD" && "DC" && "MI" && "MN" && "NJ" && "NM" && "NC" && "OR" && "SC" && "TX" && "UT" && "VA" && "WY") {
Lab = "HELIX";
}
And when I change the &&, to || instead, the state changes to "AL", the first state in the if statement
I've noticed that the last state in the IF statement is "WY," maybe my statement is not set up correctly?
Copy link to clipboard
Copied
No, it's not. There are syntax errors in it (you used "=" instead of "==", for example) as well as logical ones.
How can one variable equal multiple values? Did you mean to use the OR operator, not the AND one?
Copy link to clipboard
Copied
I meant for it to be the OR operator, and changed it after making the comment.
I inserted the "==" operator where it needed to be, and it seems to work perfectly now. It will only print the file name if a mistake is found, thank you guys for your help!
Copy link to clipboard
Copied
Post you full code, please...
Copy link to clipboard
Copied
var File = this.documentFileName.replace(/.pdf/,"");
var List = this.documentFileName.replace(/.pdf/,"");
File = File.replace(/\s/g,'');
var First = this.getField("First Name");
var Last = this.getField("Last Name");
var Middle = this.getField("Middle Initial");
var State = this.getField("State");
var Lab = "HELIX";
if (State.value == "AL" || "CT" || "FL" || "GA" || "HI" || "IL" || "KY" || "LA" || "MD" || "DC" || "MI" || "MN" || "NJ" || "NM" || "NC" || "OR" || "SC" || "TX" || "UT" || "VA" || "WY") {
Lab = "MDV";
}
var Patient = Last.value + "," + First.value + Middle.value + "-" + Lab + "-" + State.value + "-" + "RECFORM";
if (File != Patient) {
console.println(List);
}
Copy link to clipboard
Copied
This is a common error, it comes from thinking in English, where you can say "If the patent is John or Peter or Mike". But that isn't what you can say in JavaScript. You have to say "If the patient is John or the patient is Peter or the patient is Mike". So your code has to be a lot longer...
Copy link to clipboard
Copied
Yeah, this part is wrong:
if (State.value == "AL" || "CT" || "FL" || "GA" || "HI" || "IL" || "KY" || "LA" || "MD" || "DC" || "MI" || "MN" || "NJ" || "NM" || "NC" || "OR" || "SC" || "TX" || "UT" || "VA" || "WY")
It needs to be:
if (State.value == "AL" || State.value =="CT" || State.value =="FL" || State.value =="GA" || State.value =="HI" ... etc.
Copy link to clipboard
Copied
Your code would be much more efficient and there's less repetitive typing if you created an array of values to test and then test if the value is in the array. Below is a truncated example...
var states = ["AL", "CT", "FL", "GA", HI"] // Add rest of states inside array based on the example shown
if (states.indexOf(State.value) > -1) {
var Patient = Last.value + "," + First.value + Middle.value + "-" + Lab + "-" + State.value + "-" + "RECFORM";
}
Copy link to clipboard
Copied
True, that's a better approach, but a bit more complex to follow, if you're not versed in JavaScript.