Skip to main content
Ryan_Oliver_02445
Known Participant
January 18, 2019
Answered

How to print Javascript strings into console, or into a txt file

  • January 18, 2019
  • 2 replies
  • 14222 views

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.

This topic has been closed for replies.
Correct answer try67

Use this code:

console.println(File);

2 replies

try67
Community Expert
Community Expert
January 18, 2019

PS. You have multiple errors in your code...

Ryan_Oliver_02445
Known Participant
January 18, 2019

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? 

Thom Parker
Community Expert
Community Expert
January 18, 2019

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.


You probably want the "value" of the field

try this:

var Patient = Last.value + ", " + First.value + " " + Middle.value + " - " + Lab + " - " + State.value + " - " + "REC FORM";

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 18, 2019

Use this code:

console.println(File);