Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: Example of including a js function from a file

  1. #1
    Join Date
    Jun 2007
    Posts
    16

    Default Example of including a js function from a file

    Hi,

    Any one with a small example of including a JavaScript function from an external file and using it in JavascriptRule? I have a javascript function that i want to use in a couple of xaction. So calling it from an external file makes is much less error prone.

    raj

  2. #2
    Join Date
    Dec 2005
    Posts
    531

    Default

    Hi,

    I don't know if you can use a external file, but what you can do alternatively is to use a seperate action sequence that only contains your script. Use the right input and output parameters and you can call it from other action sequences. of course that does not work from within the JavaScriptRule.

    I don't know if that approach fits your usage scenario but maybe it does.

    All the best,
    Ingo

  3. #3
    Join Date
    Jun 2007
    Posts
    16

    Default

    Hi,

    The http://wiki.pentaho.org/display/PentahoDoc/JavaScript says that I can use an imported javascript. I do not want to make JS an action sequence of it's own, may be if nothing works, I might, but it seems there is a way to import the js directly.

    raj

  4. #4
    Join Date
    Dec 2005
    Posts
    531

    Default Solution

    I investigated a bit and here you go, although it was quite straight forward:

    1. Create a .js file in your solution.
    2. Create the action sequence and add a JavaScript Rule action.
    3. I the Java Script Rule editor add your file to the Imported Javascript box.
    4. call the function from your code

    Enclosed are two files with an example, just make sure you put them in the same folder otherwise the ressource path will be wrong.

    All the best,
    Ingo
    Attached Files Attached Files

  5. #5
    Join Date
    Jun 2007
    Posts
    16

    Default

    Thanks!! Posting the relevant parts for archives!

    raj

    Code:
      <resources>
        <javascript>
          <solution-file>
            <location>test.js</location>
            <mime-type>text/javascript</mime-type>
          </solution-file>
        </javascript>
      </resources>
      
      <actions> 
        <action-definition>
          <component-name>JavascriptRule</component-name>
          <action-type>JavaScript</action-type>
          <action-resources>
            <javascript type="resource"/>
          </action-resources>
          <action-outputs>
            <test_v type="string"/>
          </action-outputs>
          <component-definition>
            <script><![CDATA[test_v = test();]]></script>
          </component-definition>
        </action-definition>

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.