cancel
Showing results for 
Search instead for 
Did you mean: 

Script for launch an external URL

elenaor
Champ in-the-making
Champ in-the-making
Hi, my company needed a document management system and I chose Alfresco community v2.1. I'm actually pleased with all its features but I have some problems.
I have created a button for launch a javascript. I need that this script go to an external URL like google. I have widely readed http://wiki.alfresco.com/wiki/JavaScript_API but I couldn't find the answer. Any help would be appreciated.
Thanks in advance.
Elena.
6 REPLIES 6

gavinc
Champ in-the-making
Champ in-the-making
You can configure an action to call a script or you can define a target HREF, have a look at the externalised actions wiki page for more info: http://wiki.alfresco.com/wiki/Externalised_Client_Actions

elenaor
Champ in-the-making
Champ in-the-making
Hi,gavinc. First of all, thank you very much for your post.

I tried to define a target HREF and everthing seemed to be ok. But that didn't solve my problem. I have added to web-client-config-custom.xml the following sentences:

<config>
   <actions>
         <action id="Firmar">
         <label>Firmar</label>
         <image>/images/icons/add.gif</image>
  <params>
  <param name="nodeRef">#{actionContext.nodeRef}</param>
  </params>
  <script>/Utrera/Datos/Scripts/firma.js</script>
      <action>dialog:addAspect</action>
      </action>   
      <!– Add action to more actions menu for each space –>
      <action-group id="document_browse_menu">
         <action idref="Firmar" />
      </action-group>
   </actions>
</config>

And my javascript firma.js:

var document = search.findNode(args["nodeRef"]);
var documentName=document.name;
var contenido=document.content;

And now, here is my problem:
at the end of the script I tried to launch (without any success) the following url:
http://localhost:8080/alfresco/jsp/firma/prueba.jsp?nombreDocumento=document.name&contenidoDocumento...

I have read some script that are written by you but I can't find the answer. I tried with "window.open()",  but "window is not defined" is replied to me.

Thanks in advance.

gavinc
Champ in-the-making
Champ in-the-making
The reason is that you are running a server side JavaScript therefore the script is running inside the Rhino engine and not the browser, hence window is not a valid object.

You can add this to the end of your script to achieve what you need:

var goback = "<script>window.open('http://localhost:8080/alfresco/jsp/firma/prueba.jsp?nombreDocumento=document.name&contenidoDocumento... ')</script>";
goback;

Hope this helps.

elenaor
Champ in-the-making
Champ in-the-making
Thank you very much, gavinc. I really appreciate your work.

Finally, I tried with this:

var url = "/alfresco/jsp/firma/prueba.jsp?nombreDocumento=document.name&contenidoDocumento=document.content" ;

var html = "<script>" +
"window.location.href='" + url + "';" +
"</script>";
html;

and everything is ok.

But now, I would like to launch my script through the rule: executing a Script. I choose my script firma.js but when I add new content to my space where the rule is supposed to be executed, nothing happens. The new window is not opened. Any help?

elenaor
Champ in-the-making
Champ in-the-making
I know what is my problem, but unfortunately, I don't know how to fix it.
I'm running my script on the server side and althoug everything seems to be ok, the new window is not displayed.
I have been reading a lot of posts but anyone of them explain how to send an http get request or how can I display the answer on the client-side or, definitely, how can I solve the problem.

Thanks in advance.
Elena.

gavinc
Champ in-the-making
Champ in-the-making
It's not possible to get a window to show up on the client when you are running your script as a rule.

The rule is running on the server and is initiated by the server, therefore regardless of what your script returns it won't open a window as it won't be running in the context of a browser.