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!
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
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
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
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.)
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
Copy link to clipboard
Copied
Absolutely, here is a sample of the Array
Copy link to clipboard
Copied
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