<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ScriptTask, JRuby cannot access execution variable in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/scripttask-jruby-cannot-access-execution-variable/m-p/181908#M135038</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, as stated in the subject header, I am trying to write a simple script task in jruby, but am running into a problem wherein the script does not recognize the execution variable's existence in its scope. I'm wondering if any issue like this has been noted before and a solution exists, or whether I'm just doing something stupid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The test case I'm running is quite simple. I have a form attached to a start activity that requests a username variable. Then in my script I try execution.getVariable('username'), but no luck. I get an error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; problem evaluation script: org.jruby.embed.EvalFailedException: (NameError) undefined local variable `execution' for main&lt;img id="smileysurprised" class="emoticon emoticon-smileysurprised" src="https://connect.hyland.com/i/smilies/16x16_smiley-surprised.png" alt="Smiley Surprised" title="Smiley Surprised" /&gt;bject&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I try the same script with groovy I have no problem. My guess then, is that this is a compatibility issue, and indeed looking through the source code, it does appear groovy is given a certain degree of preferential treatment, but I haven't been able to pinpoint in the source just how I would make this work for jruby.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any explanation would be immensely helpful, as I've spent a long time exhausting a lot of avenues of possibilities for this error, thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 06 Jul 2015 15:25:53 GMT</pubDate>
    <dc:creator>andyb</dc:creator>
    <dc:date>2015-07-06T15:25:53Z</dc:date>
    <item>
      <title>ScriptTask, JRuby cannot access execution variable</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/scripttask-jruby-cannot-access-execution-variable/m-p/181908#M135038</link>
      <description>Hi, as stated in the subject header, I am trying to write a simple script task in jruby, but am running into a problem wherein the script does not recognize the execution variable's existence in its scope. I'm wondering if any issue like this has been noted before and a solution exists, or whether I</description>
      <pubDate>Mon, 06 Jul 2015 15:25:53 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/scripttask-jruby-cannot-access-execution-variable/m-p/181908#M135038</guid>
      <dc:creator>andyb</dc:creator>
      <dc:date>2015-07-06T15:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: ScriptTask, JRuby cannot access execution variable</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/scripttask-jruby-cannot-access-execution-variable/m-p/181909#M135039</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It's been a long time since I tried Jruby … but in theory if it implements the same JSR interface, it should behave the same.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I did try your example, and had the same error &lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://connect.hyland.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt; Normally, the scripting engine asks the script binding (&lt;/SPAN&gt;&lt;A href="https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/main/java/org/activiti/engine/impl/scripting/ScriptBindings.java" rel="nofollow noopener noreferrer"&gt;https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/main/java/org/activiti/engine/impl/scripting/ScriptBindings.java&lt;/A&gt;&lt;SPAN&gt;, nor in &lt;/SPAN&gt;&lt;A href="https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/main/java/org/activiti/engine/impl/scripting/VariableScopeResolver.java" rel="nofollow noopener noreferrer"&gt;https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/main/java/org/activiti/engine/impl/scripting/VariableScopeResolver.java&lt;/A&gt;&lt;SPAN&gt;) for a variable if it doesn't know about it. But that doesn't happen here. I see quite a bit of keys being tried, but not the execution. So it makes me wonder if JRuby still implements JSR 233 the same as the other scripting engines do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(googling around found this: &lt;/SPAN&gt;&lt;A href="https://github.com/jruby/jruby/wiki/Embedding-with-JSR-223" rel="nofollow noopener noreferrer"&gt;https://github.com/jruby/jruby/wiki/Embedding-with-JSR-223&lt;/A&gt;&lt;SPAN&gt; … which seems to use the same mechanism we use … but different, cause the objects are put directly into the bindings there …)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 12:25:07 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/scripttask-jruby-cannot-access-execution-variable/m-p/181909#M135039</guid>
      <dc:creator>jbarrez</dc:creator>
      <dc:date>2015-07-07T12:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: ScriptTask, JRuby cannot access execution variable</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/scripttask-jruby-cannot-access-execution-variable/m-p/181910#M135040</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay, so running the following code in a groovy script allows you to fetch strings from a form and then manipulate them in jruby. It's an odd solution though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import javax.script.Bindings;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import javax.script.ScriptEngine;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import javax.script.ScriptEngineManager;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import javax.script.SimpleBindings;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ScriptEngineManager manager = new ScriptEngineManager();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ScriptEngine engine = manager.getEngineByName("jruby");&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Bindings bindings = new SimpleBindings();&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def message = execution.getVariable('username');&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;def quote = "\"";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;message = "$quote$message$quote";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bindings.put("message", message);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;engine.eval("puts $message");&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For some reason you have to add extra quotes around the string, otherwise groovy interprets it as a variable name instead of a string and just tells you it doesn't have access to variable '(your form input string)'. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is messy though, and fraught with what I would consider bad coding practices. But hey, it works.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 14:10:17 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/scripttask-jruby-cannot-access-execution-variable/m-p/181910#M135040</guid>
      <dc:creator>andyb</dc:creator>
      <dc:date>2015-07-07T14:10:17Z</dc:date>
    </item>
  </channel>
</rss>

