02-04-2021 08:58 AM
I have followed this tutorial: https://ecmarchitect.com/alfresco-developer-series-tutorials/workflow/tutorial/tutorial.html For now, I have created a HelloWorld workflow and deployed it successfully using Alfresco Maven SDK for Alfresco 6.2. This is the part of corresponding .bpmn file that prints Hello World! in server's log:
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1">
<extensionElements>
<activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
<activiti:field name="script">
<activiti:string>logger.log("Hello, World!");</activiti:string>
</activiti:field>
</activiti:executionListener>
</extensionElements>
</sequenceFlow>
However, I need to make an API call to https://google.com, just for testing purposes. But, when I try this:
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1">
<extensionElements>
<activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
<activiti:field name="script">
<activiti:string>
var url = "https://google.com";
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
logger.log(xhr.status);
logger.log(xhr.responseText);
}};
xhr.send();
</activiti:string>
</activiti:field>
</activiti:executionListener>
</extensionElements>
</sequenceFlow>
I get this exception:
org.alfresco.scripts.ScriptException: 01030043 Failed to execute supplied script: 01030042 ReferenceError: "XMLHttpRequest" is not defined. (AlfrescoJS#3)
at org.alfresco.repo.jscript.RhinoScriptProcessor.executeString(RhinoScriptProcessor.java:287)
at org.alfresco.repo.processor.ScriptServiceImpl.executeString(ScriptServiceImpl.java:293)
at org.alfresco.repo.processor.ScriptServiceImpl.executeScriptString(ScriptServiceImpl.java:200)
Investigating, I checked this post: https://hub.alfresco.com/t5/alfresco-content-services-forum/calling-rest-service-via-rule-script/td-.... It seems (from my understanding) that I need to make the API call using a Java class and then, somehow, invoke that object from js on the .bpmn file. So:
IMPORTANT: I need to log the API Call response some way. It could be either log that you want, but I need to know if Google is answering me accordingly.
Thanks in advance!
02-06-2021 06:31 PM
Hi, thanks for reading the tutorial! You've posted almost the exact question here already and twice on stackoverflow.
I tried to help you out on SO. The summary of my advice is to not use JavaScript to make this call from Activiti but instead use a Java delegate. I included some code snippets.
In case you ever do need to make a remote API call from a web script rather than a workflow, I've included how to define the connector and make that call as well.
02-06-2021 06:31 PM
Hi, thanks for reading the tutorial! You've posted almost the exact question here already and twice on stackoverflow.
I tried to help you out on SO. The summary of my advice is to not use JavaScript to make this call from Activiti but instead use a Java delegate. I included some code snippets.
In case you ever do need to make a remote API call from a web script rather than a workflow, I've included how to define the connector and make that call as well.
02-08-2021 08:36 AM
Thank you very much and excuse me for all of my questions. I am new to Alfresco and not a developer jeje.
This is the answer I wanted! More on this video:
Explore our Alfresco products with the links below. Use labels to filter content by product module.