Can't use getAsPlainText when running batch processor

The forum to discuss the Headless version of Servoy. Web, Java and Servlet development questions can all be posted here.

Can't use getAsPlainText when running batch processor

Postby rafig » Wed Oct 20, 2010 12:27 am

Hi,
I urgently need some help.
I spent ages working on a solution that scans a folder for RTF files that need sending via email or fax.
When it finds an RTF file it finds the email or fax number in the RTF text and then sends that file as an attachment either via email or fax.
I was using the 'getAsPlainText' function on a RTF element on a form to get just the plain text and then parsing that for the bits of data I need.
Code: Select all
   fv_txt_import = elements.fv_rtf_import.getAsPlainText ( );

   // find email address if there
   var lv_str_start = plugins.fmp.position ( fv_txt_import, 'Surgery Email', 1, 1 ) + 13;
   if ( lv_str_start <= 13 ) // no email tag
   {
      mail_email = '';
   }
   else
   {
      var lv_str_finish = plugins.fmp.position ( fv_txt_import, 'Date of Birth', 1, 1 );
      mail_email = plugins.fmp.trim (plugins.fmp.middle ( fv_txt_import, lv_str_start, ( lv_str_finish - lv_str_start ) ) );
   }

   // find fax no if there
   lv_str_start = plugins.fmp.position ( fv_txt_import, 'Surgery Fax', 1, 1 ) + 11;
   if ( lv_str_start <= 11 ) // no fax tag
   {
      mail_fax_no = '';
   }
   else
   {
      lv_str_finish = plugins.fmp.position ( fv_txt_import, 'Hospital No', 1, 1 );
      mail_fax_no = plugins.fmp.trim ( plugins.fmp.middle ( fv_txt_import, lv_str_start, ( lv_str_finish - lv_str_start ) ) );
   }

This all works beautifully in Smart Client, but the idea is to have it running on the Servoy server as a Batch Process.
Unfortunately when it runs as a batch process / headless client it appears that this function (getAsPlainText) does not work! :(
I assume that batch / HC cannot access form elements and therefore I just get 'null' returned and so my routine drops thru to the 'fail' part that sends an email to the admin saying it couldn't find an email or fax no...
I hadn't been able to test on the server as a batch process until today, having spent a long time getting my code right in Smart Client and using code from an another system that is working great as a batch process that handles LOTS of files, but obviously wasn't using form elements.
My question is this...
Is there any way to get to the plain text version of an RTF field/column in Servoy using some other function? (or could Johan please add this as a new function in 5.2.3?)
or
does anyone have some cool JavaScript/RegEx that will let me pass it a complete RTF files text contents and return just the plain text from it? (I have Google'd and tried what I found to no avail)
Thanks,
Rafi
Servoy Certified Developer
Image
rafig
 
Posts: 707
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK

Re: Can't use getAsPlainText when running batch processor

Postby Harjo » Wed Oct 20, 2010 10:31 am

that's right! in a batchprocessor you can't use elements.....
the batchprocessor has no GUI!
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Can't use getAsPlainText when running batch processor

Postby rafig » Wed Oct 20, 2010 10:41 am

Harjo wrote:that's right! in a batchprocessor you can't use elements.....
the batchprocessor has no GUI!


thanks for the confirmation, but now how do I get to the plain text of the RTF?
Servoy Certified Developer
Image
rafig
 
Posts: 707
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK

Re: Can't use getAsPlainText when running batch processor

Postby Harjo » Wed Oct 20, 2010 10:43 am

Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Can't use getAsPlainText when running batch processor

Postby rafig » Wed Oct 20, 2010 3:39 pm



Harjo, I owe you a beer at ServoyWorld!!!
OMG, that did it, thank you (& Andrei) so much (at least it worked in smart client without using element)
Will now upload to client and see what happens :D

I just knew someone on the forums would have an answer...
Servoy Certified Developer
Image
rafig
 
Posts: 707
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK

Re: Can't use getAsPlainText when running batch processor

Postby Harjo » Wed Oct 20, 2010 3:58 pm

rafig wrote:Harjo, I owe you a beer at ServoyWorld!!!


DEAL! :lol:
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Can't use getAsPlainText when running batch processor

Postby rafig » Wed Oct 20, 2010 4:24 pm

Harjo, it seems to be working on the Server as a batch process/HC, so thanks again!

Whilst I'm here, can I ask if anyone knows if it is possible to get the batch process/HC running on Servoy server to be able to access Windows network shares.
This system is currently picking up the files from a directory on the local C: drive and then moving them to another folder on C: drive once processed, but the client wants it to be able to pick them up from a network drive/share, which works fine in smart client, but not when running as service...

If not, they will have to set something up (another possible point of failure...) that moves them to server...

Thanks again,

Rafi
Servoy Certified Developer
Image
rafig
 
Posts: 707
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK

Re: Can't use getAsPlainText when running batch processor

Postby mboegem » Wed Oct 20, 2010 6:00 pm

For those people wondering what about converting html formatted text:

Code: Select all
var htmlEditorKit = new Packages.javax.swing.text.html.HTMLEditorKit();
   var htmlDocument = htmlEditorKit.createDefaultDocument();
   
   var reader = new java.io.StringReader('myHtmlTextString');
   htmlEditorKit.read(reader, htmlDocument, 0);
   
   var result =  htmlDocument.getText(0, htmlDocument.getLength());

   return utils.stringTrim(result));
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1749
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam


Return to Servoy Headless Client

Who is online

Users browsing this forum: No registered users and 6 guests