Hitachi Vantara Pentaho Community Forums
Results 1 to 7 of 7

Thread: Modified JavaScript step and use of regular expressions

  1. #1
    Join Date
    May 2010
    Posts
    18

    Default Modified JavaScript step and use of regular expressions

    Hi all,

    I'm attempting to use Spoon to pull data from one forum database and store it in another forum database. Unfortunately, the posts are stored with html formatting in the source forum and need to be stored with bb code formatting in the target forum. I'm currently trying to use the Modified JavaScript Value step with regular expressions to correct the formatting. Here is the short script my colleague and I have so far:

    var a=POST.getString();
    a = a.replace(/\<img src="(.*?)".*?img>/gi,"\[img\]$1\[\/img]"); // img
    a = a.replace(/\<a href="(.*?)"\>(.*?)<\/a>/gi,"\[url=$1\]$2\[\/url]"); // href
    a = a.replace(/>/g, "]");
    a = a.replace(/</g, "[");



    POST refers to the actual post that needs to be reformatted. We've tweaked this script in multiple ways, including trying it with compatibility mode on and off. The error we keep getting when we test the script is:

    Code:
    2010/09/27 12:42:40 - Modified Java Script Value.0 - ERROR (version 4.0.0-GA, build 13347 from 2010-06-03 16.14.10 by buildguy) : Unexpected error : 
    2010/09/27 12:42:40 - Modified Java Script Value.0 - ERROR (version 4.0.0-GA, build 13347 from 2010-06-03 16.14.10 by buildguy) : org.pentaho.di.core.exception.KettleValueException: 
    2010/09/27 12:42:40 - Modified Java Script Value.0 - ERROR (version 4.0.0-GA, build 13347 from 2010-06-03 16.14.10 by buildguy) : Couldn't compile javascript: 
    2010/09/27 12:42:40 - Modified Java Script Value.0 - ERROR (version 4.0.0-GA, build 13347 from 2010-06-03 16.14.10 by buildguy) : missing ; before statement (script#1)
    2010/09/27 12:42:40 - Modified Java Script Value.0 - ERROR (version 4.0.0-GA, build 13347 from 2010-06-03 16.14.10 by buildguy) : org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.addValues(ScriptValuesMod.java:292)
    2010/09/27 12:42:40 - Modified Java Script Value.0 - ERROR (version 4.0.0-GA, build 13347 from 2010-06-03 16.14.10 by buildguy) : org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.processRow(ScriptValuesMod.java:670)
    2010/09/27 12:42:40 - Modified Java Script Value.0 - ERROR (version 4.0.0-GA, build 13347 from 2010-06-03 16.14.10 by buildguy) : org.pentaho.di.trans.step.RunThread.run(RunThread.java:40)
    2010/09/27 12:42:40 - Modified Java Script Value.0 - ERROR (version 4.0.0-GA, build 13347 from 2010-06-03 16.14.10 by buildguy) : java.lang.Thread.run(Unknown Source)
    Please help!

    Thanks!

  2. #2
    Join Date
    Sep 2009
    Posts
    810

    Default

    Hi there,

    except for the first line everything works for me

    Check out the attached sample. Works in PDI >= 3.2

    Cheers

    Slawo
    Attached Files Attached Files

  3. #3
    Join Date
    May 2010
    Posts
    18

    Default

    Thanks for the quick response!

    Excuse my ignorance here, but if I'm using a repository to store everything, where do I need to drop that file so that I can access it through Spoon? From what I understand, you can't just associate Spoon with .ktr files so that it automatically opens them, so if you could help me out and point me in the right direction here, I would really appreciate it.

    Thanks.

  4. #4
    Join Date
    Sep 2009
    Posts
    810

    Default

    Hi there,

    have you tried choosing File/Open from the menu bar?

    Cheers

    Slawo

  5. #5
    Join Date
    Apr 2008
    Posts
    4,690

    Default

    From what I recall, File -> Open changes where it looks depending on if you are connected to a repository or not.

    If you use the File -> Import from XML it will open the usual File Dialog that you can then navigate to find your file.

    Another way: Click cancel when asked to log in to the Repository. You can then use File -> Open as Slawo recommends
    **THIS IS A SIGNATURE - IT GETS POSTED ON (ALMOST) EVERY POST**
    I'm no expert.
    Take my comments at your own risk.

    PDI user since PDI 3.1
    PDI on Windows 7 & Linux

    Please keep in mind (and this may not apply to this thread):
    No forum member is going to do your work for you. We will help you sort out how to do a specific part of the work, as best we can, in the timelines that our work will allow us.
    Signature Updated: 2014-06-30

  6. #6
    Join Date
    May 2010
    Posts
    18

    Default

    I was able to open the file and it really helped clear some things up. We did try a script like that originally, but I didn't realize that, in order to see the correct results, it needed to be previewed from the Dummy step. Everything seems to be running smoothly now. Thanks so much!!!!

  7. #7
    Join Date
    Jul 2010
    Posts
    11

    Default

    POST.getString(); I think it's not supported!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.