cancel
Showing results for 
Search instead for 
Did you mean: 

Call a repository webscript from a rule script

midoscofield
Champ in-the-making
Champ in-the-making
Hello,
I want to call a repository webscript in a rule js,so i put:

var connector = remote.connect("alfresco");
var json = connector.get("/auditexample/createdDocuments.json");


After that i have an error message telling me that "remote" is undefined .
Any idea Please?
4 REPLIES 4

afaust
Legendary Innovator
Legendary Innovator
Hello,

it does not make much sense to call a Repository web script from a rule. The rule is already being executed on the Repository and can do anything the web script can do. The root object "remote" is not available on the Repository tier by default, which is why this attempt fails from a technical perspective.

Regards
Axel

midoscofield
Champ in-the-making
Champ in-the-making
Hello AFaust,

I have to go through a rule to call my repository webscript, so my question Please is : It is possible to make the Object "remote" available in my JS rule or not?And if possible how can i do it?

Thanks!

afaust
Legendary Innovator
Legendary Innovator
Hello,

your rule already is IN the Repository. Why call a web script if your rule can already contain the logic you need to execute? If you want to avoid duplication of code, simply extract logic to a JS library file which you can include in your rule JS via <blockcode><import resource=""></blockcode>.

If you really must, you may be able to make the "remote" object available by reconfiguring the Spring context. Simply add <blockcode><entry key="remote" value-ref="webframework.webscripts.scriptremote" /></blockcode> as a "scriptObject" to the bean "webscripts.container". Best you copy the bean from web-scripts-application-context.xml into an override in your extension directory.
You may also have to add a <blockcode><alfresco-config></blockcode> config file for configuring the "Remote" endpoints.

Again: You do not need "remote" to execute Repository code - simply use a JavaScript library file for common code. Using "remote" to call a Repository web script is like trying to call yourself on your phone to tell yourself to do something you could instead be doing already…

Regards
Axel

midoscofield
Champ in-the-making
Champ in-the-making
Hello Axel,
Yes that's it! i should change the process,maybe i should make a custom action ,thank you very much!