Skip to main content
Known Participant
December 19, 2017
Answered

Pulling information from specific row using importTextData

  • December 19, 2017
  • 1 reply
  • 663 views

Hello,

I am trying to fill out fields in a form by selecting a certain row in a text file. My javascript is

if (typeof cnt == "undefined") cnt = 0;

importTextData("/C/Users/Desktop/Barcodes/filename.txt", 3)

With the above code i am able to fill out my form using information from the 3rd row in the text file. What i would like to do is fill out information based on the value of the first column. For instance, my text file looks like this

F. Name   Gender    email

Jon               M          test@testing.com

Victoria         F           sample@testing.com

Tom              M          test123@testing.com

I would like to import the data based on the value of column one. So if column one equaled "Tom" import that row.

Is this possible?

Thanks

This topic has been closed for replies.
Correct answer try67

You can use something like this:

var result = 0;

var cnt = 0;

while (result==0) {

    result = this.importTextData("/C/Users/Desktop/Barcodes/filename.txt", cnt);

    if (this.getField("Name").valueAsString=="Tom") break;

    cnt++;

}

if (result!=0) {

     app.alert("Error!");

     this.resetForm();

}

1 reply

try67
Community Expert
Community Expert
December 19, 2017

You can use a loop to import row by row, stopping when you hit the value you're after.

Known Participant
December 19, 2017

Hmm... how would i implement a while loop into this.

I essentially would like to import text data if F.Name[] == "Tom" in this case. 

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 19, 2017

You can use something like this:

var result = 0;

var cnt = 0;

while (result==0) {

    result = this.importTextData("/C/Users/Desktop/Barcodes/filename.txt", cnt);

    if (this.getField("Name").valueAsString=="Tom") break;

    cnt++;

}

if (result!=0) {

     app.alert("Error!");

     this.resetForm();

}