Create Export to text from SeachEngine

lock
push_pin
done
Answered
4

Hi,

I would like to use SeachEngine to collect data from a custom table and exports the result to a .txt file.

If I use the print command it will create a html file, but how can I store it in a text file?

regards,

Niels

6 Dec 2016 | 12:00 AM

All Replies (4)

Hi Niels,

Is this something you're looking for?

File f;
f.open("c:\\temp\\export_file.csv", "a+");
f.write("col1;col2;col3;col4\n");

SearchEngine se;
se.bypassNetServer(true);
se.addField("y_custom_table.x_field_1");
se.addField("y_custom_table.x_field_2");
se.addField("y_custom_table.x_field_3");
se.addField("y_custom_table.x_field_4");

for(se.select(); !se.eof(); se.next())
{
  f.write(se.getField(0) + ";" + se.getField(1) + ";" + se.getField(2) + ";" + se.getField(3) + "\n");
}

You could also create the csv file as an attachment

String output = "col1;col2;col3;col4\n";

SearchEngine se;
se.bypassNetServer(true);
se.addField("y_custom_table.x_field_1");
se.addField("y_custom_table.x_field_2");
se.addField("y_custom_table.x_field_3");
se.addField("y_custom_table.x_field_4");

for(se.select(); !se.eof(); se.next())
{
  output.append(se.getField(0) + ";" + se.getField(1) + ";" + se.getField(2) + ";" + se.getField(3) + "\n");
}

String encoded = encodeBase64(output.toByteArray());

Attachment att;
att.setValue("name", "Exported data");
att.setValue("contentType", text/csv");
Integer attId = att.save();
att.saveBase64(encoded);

If I understood your request, that is :)

6 Dec 2016 | 12:00 AM

Hi Simen,

Yes, this is definitely what I meant!

I am gonna try both (just to see how it works). :)

But since this has to run in online, I think the second option is easier.

thanxs a lot, man!

Regards, niels

6 Dec 2016 | 12:00 AM

Just glad to be of help :)

You could also send the attachment to your email as well.

 

I should mention that in Online if the script takes too long to run or takes too much memory, it will fail. But you'll get a notification saying so.

6 Dec 2016 | 12:00 AM

Hi Simen,

This works great! Adding the file to an email was a piece of cake after this.

Thanks,

Niels

26 Dec 2016 | 12:00 AM

Add reply