Searching a value in CSV then fill a form.

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
Daivana
Posts: 19
Joined: Sat Sep 04, 2010 8:58 am

Searching a value in CSV then fill a form.

Post by Daivana » Wed Oct 20, 2010 9:01 am

Hello.


I would love to know if a macro could search a CSV file for a specific value and when it founds one then it gets all other data for a form to fill.

Example.

COL1____COL2_____COL3
One______A _______B
Two _____B_______C


When the macro finds for example the word "One" it gets the A and B and fills the apropirate fields.

Image


I would really appriciate some direction for solution.
Daivana
Posts: 19
Joined: Sat Sep 04, 2010 8:58 am

Re: Searching a value in CSV then fill a form.

Post by Daivana » Sun Oct 24, 2010 8:48 am

Please could I get some answer to it if it is possible or not?
iToo
Posts: 13
Joined: Mon Oct 18, 2010 2:28 am

Re: Searching a value in CSV then fill a form.

Post by iToo » Mon Oct 25, 2010 2:20 am

Daivana wrote:Please could I get some answer to it if it is possible or not?
Good question, interested to know aswell!
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

Re: Searching a value in CSV then fill a form.

Post by Tom, Tech Support » Mon Oct 25, 2010 11:05 am

Hello,

The most efficient way would be to write a Javascript to process the file and search for the value yourself. Or, you could use the following script and macro code to sequentially search through the file looking for the value, although this will be much slower for larger files.

Code: Select all

var ret;

try
	{
	checkErr(iimPlay("CODE:PROMPT Please<SP>enter<SP>the<SP>search<SP>value: !VAR1\nSET !EXTRACT {{!VAR1}}"));
	var searchVal = iimGetLastExtract(1);
	var currentVal;
	
	var row = 2; // Start with row 2 to skip header row
	
	while (true)
		{
		checkErr(iimSet("row", row));
		ret = iimPlay("LoopFile");
		
		if (ret == -951) // Check for EOF
			{
			checkErr(iimSet("searchVal", searchVal));
			checkErr(iimPlay("CODE:PROMPT {{serachVal}}<SP>was<SP>not<SP>found<SP>in<SP>CSV<SP>file!"));
			break;
			}
			
		checkErr(ret); // Check for other errors
			
		currentVal = iimGetLastExtract(1);
		
		if (currentVal == searchVal)
			{
			checkErr(iimSet("row", row));
			checkErr(iimPlay("FillForm"));
			break;
			}
		row++;
		}
	}
catch (e)
	{
	alert(e.toString() + ": " + iimGetLastError());
	}
	
function checkErr(retCode)
{
	if (retCode < 0)
		{
		throw retCode;
		}
	return;
}
LoopFile.iim:

Code: Select all

SET !DATASOURCE Address.csv
SET !DATASOURCE_COLUMNS 8
SET !DATASOURCE_LINE {{row}}

SET !EXTRACT {{!COL1}}
Regards,

Tom, iMacros Support
Daivana
Posts: 19
Joined: Sat Sep 04, 2010 8:58 am

Re: Searching a value in CSV then fill a form.

Post by Daivana » Thu Oct 28, 2010 9:38 am

I am really thankful for the help, I know that easier is to make a javascript for the job without imacro.
I am trying to understand how the code works, everything is fine but the script wont find the value in csv file, I tried to tinker a little the both scripts but no avail.

I want to know this peace of code

Code: Select all

if (currentVal == searchVal)
         {
         checkErr(iimSet("row", row));
         checkErr(iimPlay("FillForm"));
         break;
         }
the FillForm.iim is for example where to put the imacro script for filling my form?


----------------------

This is solved
Last edited by Daivana on Thu Nov 04, 2010 3:04 pm, edited 1 time in total.
Daivana
Posts: 19
Joined: Sat Sep 04, 2010 8:58 am

Re: Searching a value in CSV then fill a form.

Post by Daivana » Tue Nov 02, 2010 9:19 pm

The script is working just fine, but I would like to have some help.

When I execute the javascript I have to tipe what I am searching for, but how would I make that the script, when executed, searches for a value when it is tipped allready in a field.

Right now it just fills values from one row, but how should it get the second row value?


The script for now is:

The js I had been provided.

Code: Select all

var ret;

try
   {
   checkErr(iimPlay("CODE:PROMPT Please<SP>enter<SP>the<SP>search<SP>value: !VAR1\nSET !EXTRACT {{!VAR1}}"));
   var searchVal = iimGetLastExtract(1);
   var currentVal;
   
   var row = 1; // Start with row 2 to skip header row
   
   while (true)
      {
      checkErr(iimSet("row", row));
      ret = iimPlay("LoopFile");
      
      if (ret == -951) // Check for EOF
         {
         checkErr(iimSet("searchVal", searchVal));
         checkErr(iimPlay("CODE:PROMPT {{searchVal}}<SP>was<SP>not<SP>found<SP>in<SP>CSV<SP>file!"));
         break;
         }
         
      checkErr(ret); // Check for other errors
         
      currentVal = iimGetLastExtract(1);
      
      if (currentVal == searchVal)
         {
         checkErr(iimSet("row", row));
         checkErr(iimPlay("GLPIFIller"));
         break;
         }
      row++;
      }
   }
catch (e)
   {
   alert(e.toString() + ": " + iimGetLastError());
   }
   
function checkErr(retCode)
{
   if (retCode < 0)
      {
      throw retCode;
      }
   return;
}
LoopFile.iim

Code: Select all

SET !DATASOURCE Address.csv
SET !DATASOURCE_COLUMNS 5
SET !DATASOURCE_LINE {{row}}
'PROMPT {{!COL1}}

SET !EXTRACT {{!COL1}}
And the Fill form script.

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:form_ticket ATTR=NAME:track_data1 CONTENT=

TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:form_ticket ATTR=NAME:track_data2 CONTENT={{row}}

TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:form_ticket ATTR=NAME:track_data3 CONTENT={{row}}
So I would know how to get the value from second row and fill the field, could be I am missing a thing, what peace of code?

I know that in the javascript the

Code: Select all

 row++;
is something like loop or adding + one value or step to the next value, but I dont really understand how to get the other value.


Please an answer would help :)
Post Reply