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

Problems retrieving the Index of a value in an array

  • January 24, 2019
  • 2 replies
  • 1725 views

Good evening, I am creating an array that will allow total automation of our company's work.

However, I am running into the problem of not being able to find the Index of values, which are grabbed from the form fields in the PDF.

Here is my code:

  

this.importDataObject("MEDDIAGNOSISICD-10.txt", "C:\Users\dell\Documents\tab excel\MEDDIAGNOSISICD-10.txt");

var oFile = this.getDataObjectContents("MEDDIAGNOSISICD-10.txt");

var cFile = util.stringFromStream(oFile, "utf-8");

var fileArray = cFile.split('\n');

var Med = this.getField("Medications 1");

var Index = fileArray.indexOf("Med.value");

var Search = fileArray[Index.value];

console.println(Index);

The results always come back as "-1."

Any help would be greatly appreciated!

This topic has been closed for replies.
Correct answer BarlaeDC

Hi,

You code appears to be checking for the value "Med.value" not the value contained by Med.

Change this line

var Index = fileArray.indexOf("Med.value");

to

var Index = fileArray.indexOf(Med.value);

Hope this helps

Malcolm

2 replies

BarlaeDC
BarlaeDCCorrect answer
Adobe Expert
January 25, 2019

Hi,

You code appears to be checking for the value "Med.value" not the value contained by Med.

Change this line

var Index = fileArray.indexOf("Med.value");

to

var Index = fileArray.indexOf(Med.value);

Hope this helps

Malcolm

Ryan_Oliver_02445
Known Participant
January 25, 2019

I fixed the file path, and I found that separating the file by tabs works well in getting rid of the spaces, with each med and their code in the same line.

The Array is set up like this in string form:

   Medication,Brand,Diagnosis,Code

This set of code can call a specific string, set it to a variable, and print it into the console now:

this.importDataObject("MEDDIAGNOSISICD-10.txt", "C:/Users/dell/Documents/tab excel/MEDDIAGNOSISICD-10.txt");

var oFile = this.getDataObjectContents("MEDDIAGNOSISICD-10.txt");

var cFile = util.stringFromStream(oFile, "utf-8");

var fileArray = cFile.split('\t');

var Med = this.getField("Medications 1");

var Index = fileArray.indexOf(Med.value);

var Call = fileArray[Index];

console.println(Call);

However, now I'm stuck with calling the only the Medication being called,, and not the full line it is in, sadly.

The goal is to be able to scan for the Medication, and be able to get the Medication's Brand, Code, an Diagnosis (which are all in the same line.)

BarlaeDC
Adobe Expert
January 25, 2019

Hi,

Can you share a sample input text document so we can see what the array looks like that we are dealing with, in which case we may be able to guide you? (Use a file sharing site, and it doesn't have to be the real data, just represent it so we can get the information you want)

Regards

Malcolm

Thom Parker
Adobe Expert
January 24, 2019

Obviously the array does not contain the value passed into "indexOf".

Print out split string to see exactly what's in there

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often