• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Problems retrieving the Index of a value in an array

Explorer ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

806

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 25, 2019 Jan 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

Votes

Translate

Translate
Community Expert ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2019 Jan 25, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 25, 2019 Jan 25, 2019

Copy link to clipboard

Copied

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.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2019 Jan 25, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 25, 2019 Jan 25, 2019

Copy link to clipboard

Copied

Absolutely, here is a sample of the Array

File sharing and storage made simple

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 25, 2019 Jan 25, 2019

Copy link to clipboard

Copied

LATEST

Update:  So here is the code I have 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('\n');

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

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

var Call = fileArray[Index];

var i, Index;

for (i = 0; i < fileArray.length; i++) {

  Index = fileArray.indexOf(Med.value);

  if(Index > -1) console.println(fileArray);

}

It now brings up all instances of the medication, and its full line.

The final step is to be able to extract the individual values in the string, and assign them to variables, so that way I can write the variables into a Form field

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines