<?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 Re: Access uploaded file in Groovy Script in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11900#M5249</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Greg,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you do&amp;nbsp;something like this in a script task, or would you have to use a service task? The example you pointed me to seems to use Java, but script tasks can only take JavaScript or Groovy, correct?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Jun 2017 18:27:22 GMT</pubDate>
    <dc:creator>jvaidya</dc:creator>
    <dc:date>2017-06-02T18:27:22Z</dc:date>
    <item>
      <title>Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11894#M5243</link>
      <description>I'm trying to Base64 encode a file that a user uploads in an Activiti form, and then save the resulting encoding as a string to be accessed by other parts of the business process. I thought a Groovy Script in a Script task would be the best way to do this. How do I access the file in the script?&amp;nbsp;Wou</description>
      <pubDate>Thu, 01 Jun 2017 19:24:40 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11894#M5243</guid>
      <dc:creator>jvaidya</dc:creator>
      <dc:date>2017-06-01T19:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11895#M5244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nope, When you upload a file it is registered as related content (Enterprise Edition) or as an attachment (Community Edition).&lt;/P&gt;&lt;P&gt;You will need to use the relatedContentService to retrieve the uploaded files for the process instance (Enterprise Edition).&lt;BR /&gt;More details here:&amp;nbsp;&lt;A __default_attr="224630" __jive_macro_name="thread" _jive_internal="true" class="jive_macro_thread jive_macro link-titled" href="https://community.alfresco.com/thread/224630-alfresco-activiti-app-showing-attached-process-and-task-documents" rel="nofollow noopener noreferrer"&gt;&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; if using Community Edition you can get to the attachments you use taskService.getTaskAttachments(taskid).&lt;/P&gt;&lt;P&gt;This will return a list of atachments from which you can retrieve the content.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;P&gt;&lt;A href="https://migration33.stage.lithium.com/t5/tag/bp3/tg-p"&gt;&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jun 2017 22:14:27 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11895#M5244</guid>
      <dc:creator>gdharley</dc:creator>
      <dc:date>2017-06-01T22:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11896#M5245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Greg! Very helpful! I tried calling the API from a Script Task, but I can't use jQuery or vanilla JavaScript AJAX calls. The error I get from Activiti is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Caused by: &amp;lt;eval&amp;gt;:5 ReferenceError: "XMLHttpRequest" is not defined&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I access this API if I can't use XML Http Requests?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: I tried following this :&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/thread/222552"&gt;What is the best way to call REST API from Activiti? Can I use JavaScript's URL redirection?&lt;/A&gt;&amp;nbsp; but I get an "'importPackage' is not defined" error.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jun 2017 15:43:45 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11896#M5245</guid>
      <dc:creator>jvaidya</dc:creator>
      <dc:date>2017-06-02T15:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11897#M5246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jay,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Script tasks actually run on the server side, even though they use Javascript (via embedded Nashorn/Rhino engine) or groovy.&lt;/P&gt;&lt;P&gt;Therefore you dont need to access the Ajax request.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Look up script tasks here:&amp;nbsp;&lt;A class="link-titled" href="https://www.activiti.org/userguide/#bpmnScriptTask" title="https://www.activiti.org/userguide/#bpmnScriptTask" rel="nofollow noopener noreferrer"&gt;Activiti User Guide - Script Task&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jun 2017 17:09:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11897#M5246</guid>
      <dc:creator>gdharley</dc:creator>
      <dc:date>2017-06-02T17:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11898#M5247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How do I access the file using relatedContentService? The link you pointed me to in the original answer uses REST API calls, so I got a little confused! Sorry about that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you point me to the documentation for relatedContentService?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jun 2017 18:10:28 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11898#M5247</guid>
      <dc:creator>jvaidya</dc:creator>
      <dc:date>2017-06-02T18:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11899#M5248</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately there is no documentation on related content service.&lt;BR /&gt;You can check for example use here:&lt;BR /&gt;&lt;A __default_attr="226112" __jive_macro_name="thread" _jive_internal="true" class="jive_macro_thread jive_macro link-titled" href="https://community.alfresco.com/thread/226112-how-do-you-access-an-uploaded-file-in-a-downstream-service-task" rel="nofollow noopener noreferrer"&gt;&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jun 2017 18:20:48 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11899#M5248</guid>
      <dc:creator>gdharley</dc:creator>
      <dc:date>2017-06-02T18:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11900#M5249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Greg,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you do&amp;nbsp;something like this in a script task, or would you have to use a service task? The example you pointed me to seems to use Java, but script tasks can only take JavaScript or Groovy, correct?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jun 2017 18:27:22 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11900#M5249</guid>
      <dc:creator>jvaidya</dc:creator>
      <dc:date>2017-06-02T18:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11901#M5250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, it is java code, but if you set the script task language to groovy then you can effectively write java code in a script task.&lt;/P&gt;&lt;P&gt;Obviously if the code is complex you would use a service task, but for simple things like pulling the instance/task attachments it is only a few lines of code (&amp;lt;10) so a script task if ok.&lt;BR /&gt;The only real downside to a script task is the fact that you cannot debug your code and dont have the toot support you would have with a java IDE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jun 2017 18:38:03 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11901#M5250</guid>
      <dc:creator>gdharley</dc:creator>
      <dc:date>2017-06-02T18:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11902#M5251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Greg. I'm a little lost without documentation, so not sure how to use relatedContentService. Would something like this work?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fileVar = "content"&lt;/P&gt;&lt;P&gt;file = relatedContentService.getFieldContentForProcessInstance(&lt;SPAN style="color: #727174; background-color: #ffffff;"&gt;&amp;nbsp;execution.getProcessInstanceId(), fileVar, 1, 0).getContent(); &amp;lt;- what format would file be in and what methods of relatedContentService do I use?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;is = file.getStream() &amp;lt;-&amp;nbsp;Another questionable line&amp;nbsp;&lt;BR /&gt;val = is.read()&lt;BR /&gt;output = ""&lt;BR /&gt;while(val != -1){&lt;BR /&gt; output += val&lt;BR /&gt;}&lt;BR /&gt;execution.setVariable('raw', output)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jun 2017 18:52:10 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11902#M5251</guid>
      <dc:creator>jvaidya</dc:creator>
      <dc:date>2017-06-02T18:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11903#M5252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this in a groovy script task.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;import com.activiti.service.runtime.RelatedContentService;&lt;BR /&gt;import com.activiti.service.runtime.RelatedContentStreamProvider;&lt;BR /&gt;import com.activiti.domain.runtime.RelatedContent;&lt;BR /&gt;import java.io.InputStream;&lt;BR /&gt;import org.apache.commons.io.IOUtils;&lt;BR /&gt;import java.nio.charset.StandardCharsets;&lt;/P&gt;&lt;P&gt;String fileVariableName = "myFile"; &lt;BR /&gt;List&amp;lt;RelatedContent&amp;gt; contentList = relatedContentService.getFieldContentForProcessInstance(execution.getProcessInstanceId(), fileVariableName, 1, 0).getContent();&lt;BR /&gt;RelatedContent content = contentList.get(0);&lt;BR /&gt;out.println("GDH :" + content.getName());&lt;BR /&gt;InputStream is = relatedContentStreamProvider.getContentStream(content);&lt;BR /&gt;String result = IOUtils.toString(is, StandardCharsets.UTF_8);&lt;BR /&gt;out.println("GDH:" + result);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Apologies but ALfresco has not documented any of these services.&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;P&gt;&lt;A href="https://migration33.stage.lithium.com/t5/tag/bp3/tg-p"&gt;&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jun 2017 20:48:24 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11903#M5252</guid>
      <dc:creator>gdharley</dc:creator>
      <dc:date>2017-06-02T20:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11904#M5253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks so much that's really helpful! Unfortunately, I'm getting this error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;problem evaluating script: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: relatedContentService for class: Script1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any thoughts?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jun 2017 21:04:39 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11904#M5253</guid>
      <dc:creator>jvaidya</dc:creator>
      <dc:date>2017-06-02T21:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11905#M5254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No idea, I built this just now in my 1.6.1 environment and it runs ok (Process Services 1.6.1 on Tomcat).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jun 2017 21:15:08 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11905#M5254</guid>
      <dc:creator>gdharley</dc:creator>
      <dc:date>2017-06-02T21:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11906#M5255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Managed to solve this issue! We had to change the activiti-app.properties configuration file to set:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Beans whitelisting&lt;BR /&gt;beans.whitelisting.enabled=false&lt;/P&gt;&lt;P&gt;# EL whitelisting&lt;BR /&gt;el.whitelisting.enabled=false&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jun 2017 17:14:57 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11906#M5255</guid>
      <dc:creator>jvaidya</dc:creator>
      <dc:date>2017-06-06T17:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Access uploaded file in Groovy Script</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11907#M5256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ahh yes, Alfresco in their infinite wisdom decided to lock down security by disabling access to beans without telling anyone in 1.6.&lt;/P&gt;&lt;P&gt;Should have thought of that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;P&gt;#bp3&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Jun 2017 14:36:22 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/access-uploaded-file-in-groovy-script/m-p/11907#M5256</guid>
      <dc:creator>gdharley</dc:creator>
      <dc:date>2017-06-09T14:36:22Z</dc:date>
    </item>
  </channel>
</rss>

