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? 

Ryan_Oliver_02445
Known Participant
January 18, 2019

You probably want the "value" of the field

try this:

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


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?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 18, 2019

Use this code:

console.println(File);