cancel
Showing results for 
Search instead for 
Did you mean: 

remote is not defined

jeremiebal
Confirmed Champ
Confirmed Champ
Hi all

In a workflow i want to retrieve history of this workflow at each task.

So i created a javascript code that i tested on my javascript console on alfresco (admin tools). And it works perfectly !


var connector = remote.connect("alfresco");
var user = connector.call("ervice/api/login?u=admin&pw=password").toString();
var indexHeadFin = user.indexOf(">");
var ticket = user.substring(indexHeadFin+10);
var indexFin = ticket.indexOf("<");
ticket = ticket.substring(0, indexFin);

var result = connector.call("ervice/api/workflow-instances/activiti$121407?includeTasks=true&alf_ticket="+ticket);
logger.warn(result.toString());


So i put this one in my workflow in a taskListener of a UserTask.
But now, this one doesn't want to run.
I have this error "remote is not defined".

And yet i have added a key in "web-scripts-application-context.xml" like i see on the Net :


<bean id="webscripts.container" class="org.alfresco.repo.web.scripts.TenantRepositoryContainer" parent="webscripts.abstractcontainer" init-method="setup">
   <property name="configService" ref="webscripts.config" />
   <property name="name"><value>Repository</value></property>
   <property name="scriptObjects">
      <map merge="true">
         …
         <entry key="remote">
            <ref bean="webscripts.script.remote" />
         </entry>   
         …


My question : how can i define "remote" to use this one on javascript in a workflow ?

Thanks a lot !
4 REPLIES 4

scouil
Star Contributor
Star Contributor
Hi,

"remote" is defined in Surf, hence is only available in Share webscripts, since only Share is built on Surf.
So same goes for the webscripts.script.remote bean. You cannot include it in alfresco side as it's defined in Surf.

But that's fine actually because it just prevented you from making an architecture mistake.
When you're in Alfresco code, you don't want to get out of it by calling a webscript that will re-enter the Alfresco context.
What you'd want is actually to directly do something similar that the webscript you planned to call.
It most likely heavily relies on an Alfresco service and using that same service will lead you to the same result.

Hi, thanks a lot for your answer.
So if i understand you, i would call an Alfresco Service wich allow to get historic of the workflow.
But, i searched and i found only the Webscript, no Alfresco Service 😕
I continue my searchs but if you could say to me what service did you talk, it would be great 🙂

scouil
Star Contributor
Star Contributor
Hi,

That's where Open source is awesome!
Basically, is that webscript does it, so can you.

So the webscript you are calling is:
GET /alfresco/s/api/workflow-instances/{workflow_instance_id}?includeTasks={includeTasks?}
If you list the webscripts on your Alfresco you'll end up on that page:
http://localhost:8080/alfresco/s/script/org/alfresco/repository/workflow/workflow-instance.get
Which tells you it's a java-backed webscript where the corresponding java class is:
Implementation:   class org.alfresco.repo.web.scripts.workflow.WorkflowInstanceGet

Looking at Alfresco code, you'll find the said class there:
https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/COMMUNITYTAGS/V4.2f/root/projects/remot...
(since you mentioned your version is 4.2 I picked 4.2.f in that link. Other versions are available too)

The key to get it done is:
workflowService.getWorkflowById(workflowInstanceId);


So if you want wour workflow to be backed in Java that's what you should use.

If you want to work in Javascript, ignore the big wall of text above.
Javascript has a root item to play with workflows. Play around with it and see if it does what you want:
http://docs.alfresco.com/4.2/references/API-JS-WorkflowManager.html

Thanks a lot !!!

As i want to work in javascript, i will use all worklowManager possibilities in my code.

🙂

Thanks again