Quantcast
Channel: PTC Community: Message List
Viewing all articles
Browse latest Browse all 12488

Re: Modular Client Side Triggers

$
0
0

I just started working on triggers and came to the same question that Scott had in mind.

First of all the best way is probably to write your own Java custom code and add it as Jeremy tried to explain.

Yet, including one's custom JavaScript code is feasible,too ...but I don't know if it's recommendable ;-)

 

Here is a kind of "Proof of Concept" which I tested with the breakLockNotification.js script. I added the following code

to the end of that script:

 

// 1. Load the script you'd like to execute
var content = new String(new java.util.Scanner(new java.io.File("C:/Program Files/MKS/IntegrityServer2009/data/triggers/scripts/samples/testeval.js")).useDelimiter("\\Z").next());


// 2. Evaluate the loaded code

eval(content.toString());

 

// 3. Execute the freshly evaluated code

multiply_xy();

 

// 4. Mail me the result of the executed code. Use your own mail address!

environmentBean.sendMail( emailTo, emailTo, "content", z.toString());

 

The code I evaluated was fairly simple ...and stupid :-) testeval.js is:

 

var x = 10;

var y = 20;

var z = 0;

 

function multiply_xy()

{

    z = x*y;

}

 

This can be a way to include other JavaScript sources into your trigger scripts, but it comes with all the side-effects that one get's from using "eval()".

E.g. you have to ponder if it is fine for you that the execution of the code is slowed down by the use of "eval()"

For for further readings on "eval()" I'd recommend "eval() isn’t evil, just misunderstood"  by Nicholas C. Zakas.

 

By the way, you can evaluate my "Proof of conecept" without compromising your sacred Integrity server if you download "Rhino" and the
"Bean Scripting Framework". Beforehand you might want to read "Making BSF and Rhino work" .


Viewing all articles
Browse latest Browse all 12488

Trending Articles