Topic
  • 7 replies
  • Latest Post - ‏2013-10-21T20:06:47Z by mark99
sblex
sblex
15 Posts

Pinned topic ITIM Javascript library

‏2010-09-17T16:59:51Z |
Hi all,

Is there a way to declare a javascript library (.js files) in TIM for scripting zones to reduce code redundancy? Thank you.
Updated on 2010-10-12T10:19:30Z at 2010-10-12T10:19:30Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    9855 Posts

    Re: ITIM Javascript library

    ‏2010-10-12T10:19:30Z  
    Hi,

    You can not literally declare .js file, but you can achieve this by coding your own JavaScript Extension.
    You'll find a tutorial and example here => http://publib.boulder.ibm.com/tividd/td/ITIM/SC32-1683-00/en_US/HTML/javascript/javascript.html

    Regards,
    /b
  • mark99
    mark99
    26 Posts

    Re: ITIM Javascript library

    ‏2013-06-14T08:06:20Z  

    I use Tim 5.1 and the JavaScript I use in workflows and provision policies has been steadily growing. I 'm now at point that I want to put some pieces in global javascript functions to reduce code redundancy and I 'm looking at the best way of doing this.

    Looking at the javascript extensions my understanding is that they are written in pure java.  So instead of brushing up my existing javascript code I have to learn the itim API and rewrite my code.

  • TerryYau
    TerryYau
    24 Posts

    Re: ITIM Javascript library

    ‏2013-06-14T14:48:12Z  
    • mark99
    • ‏2013-06-14T08:06:20Z

    I use Tim 5.1 and the JavaScript I use in workflows and provision policies has been steadily growing. I 'm now at point that I want to put some pieces in global javascript functions to reduce code redundancy and I 'm looking at the best way of doing this.

    Looking at the javascript extensions my understanding is that they are written in pure java.  So instead of brushing up my existing javascript code I have to learn the itim API and rewrite my code.

    Hi mark99,

    If I recall from my previous experience correctly, here's what you can try.

    In the scriptextention property file, allow direct java call to the File or FileReader class.  This will allow you to read file content into scripting context, convert the bytestream into string.  Then simply call the eval function to evaluate (run) the read in content (now a long string).  The eval function can run multiple lines of code, so that should be fine.  In short, a few lines of code in the scripting context will act as an "#include" or "import" statements, and run.

    Take this with a large pinch of salt as I can't recall exactly how I did this in the past.

    Updated on 2013-06-14T14:52:07Z at 2013-06-14T14:52:07Z by TerryYau
  • Andyp
    Andyp
    3 Posts

    Re: ITIM Javascript library

    ‏2013-06-14T15:19:39Z  
    • TerryYau
    • ‏2013-06-14T14:48:12Z

    Hi mark99,

    If I recall from my previous experience correctly, here's what you can try.

    In the scriptextention property file, allow direct java call to the File or FileReader class.  This will allow you to read file content into scripting context, convert the bytestream into string.  Then simply call the eval function to evaluate (run) the read in content (now a long string).  The eval function can run multiple lines of code, so that should be fine.  In short, a few lines of code in the scripting context will act as an "#include" or "import" statements, and run.

    Take this with a large pinch of salt as I can't recall exactly how I did this in the past.

    I was going to suggest the same thing as an alternative.   Here is an article from Stephen Swann that may help.

     

    http://blog.stephen-swann.co.uk/2011/03/how-to-externalise-javascript-in-itim.html

  • TerryYau
    TerryYau
    24 Posts

    Re: ITIM Javascript library

    ‏2013-06-14T15:48:58Z  
    • Andyp
    • ‏2013-06-14T15:19:39Z

    I was going to suggest the same thing as an alternative.   Here is an article from Stephen Swann that may help.

     

    http://blog.stephen-swann.co.uk/2011/03/how-to-externalise-javascript-in-itim.html

    Perfect example!  Thanks for the link!

    Looks like we all need something like this.  Maybe IBM should consider building this feature into the product, in a more managed manner (e.g. able to select from GUI which scripts to include in which context).

  • mark99
    mark99
    26 Posts

    Re: ITIM Javascript library

    ‏2013-06-14T19:17:04Z  
    • TerryYau
    • ‏2013-06-14T14:48:12Z

    Hi mark99,

    If I recall from my previous experience correctly, here's what you can try.

    In the scriptextention property file, allow direct java call to the File or FileReader class.  This will allow you to read file content into scripting context, convert the bytestream into string.  Then simply call the eval function to evaluate (run) the read in content (now a long string).  The eval function can run multiple lines of code, so that should be fine.  In short, a few lines of code in the scripting context will act as an "#include" or "import" statements, and run.

    Take this with a large pinch of salt as I can't recall exactly how I did this in the past.

    I have been experimenting with this approach. But I 'm not convinced if this is the right approach for the following reasons

    - eval is evil, so I am told.

    - I created a somewhat more complicated operation where I use a connection to an external database using java calls. This did not work.

    - I fear for performance issues

  • mark99
    mark99
    26 Posts

    Re: ITIM Javascript library

    ‏2013-10-21T20:06:47Z  
    • mark99
    • ‏2013-06-14T19:17:04Z

    I have been experimenting with this approach. But I 'm not convinced if this is the right approach for the following reasons

    - eval is evil, so I am told.

    - I created a somewhat more complicated operation where I use a connection to an external database using java calls. This did not work.

    - I fear for performance issues

    The lack of a global jscript library kept on bugging me.

    I have adaped the SampleGlobalExtension example program  to hold a string containing the javascript library so the library is kept in memory.

    In the javascript code I can than do some thing

    eval(jslib);
    result=globalFunction();

    I can even do a call to reload the library during testing/development so i don't have to restart the server

    reloadjslib();

    It is still a bit of an experiment but seems promising