cancel
Showing results for 
Search instead for 
Did you mean: 

how to reach an url using script?

tarl
Champ in-the-making
Champ in-the-making
Hello everyone!
I'm working on a project on alfresco and Redmine. I need to know if there is a script which can call an url.
Moreover I want to know how to create a button to execute a script.
thx
3 REPLIES 3

jpotts
World-Class Innovator
World-Class Innovator
If by "button that can call a script" you mean you want something in Explorer that would call server-side JavaScript, what you need to do is write a UI Action that calls the "execute script" action and gives it the name of the script you want to run. There's a chapter in the Alfresco Developer Guide that shows how to do this, but in that example the person that clicks the button gets to choose which script to run. It's not a big deal to hardcode which script gets run.

If you just want the UI action to invoke a URL you can do that too. For example (another one from the book):

<config> 
  <actions>
    <!– Link to SomeCo's Web Site –>
    <action id="web_site">
      <label>SomeCo</label>
      <href>http://www.optaros.com</href>
      <image>/someco/images/icons/website.gif</image>
      <target>new</target>
    </action>
    <action-group id="document_browse">
      <action idref="web_site" />
    </action-group>
    <action-group id="document_browse_menu">
      <action idref="web_site" />
    </action-group>
    <action-group id="doc_details_actions">
      <action idref="web_site" />
    </action-group>
  </actions>
</config>
The above is a section from web-client-config-custom.xml that would create a link to a web site and then add that link to several of the UI action menus in Alfresco.

If, by "script that can call a URL" you mean you wan to be able to make a remote connection to some other web site from a server-side JavaScript running in Alfresco, that's also do-able, but something else entirely.

Jeff

tarl
Champ in-the-making
Champ in-the-making
Hello jpotts!
Thx for your answer! I've read your book and with your help the simple UI Action is working. However I need that, using the simple script of alfresco data dictionnary, I could run an AJAX request calling the wanted website.

for exemple something like that directly in my script :


//some simple script instruction :
document.transformDocument("application/pdf", space)
document.remove()

//and now something for the ajax call wich obviously doesn't work ! :

var bindArgs = {           
     url: "www.google.com",
     method: "post",           
     mimetype: "text/html",           
     //load: function(type,data,evt)  {Callback script executed after the AJAXcall}  
                                                                                   };   
dojo.require("dojo.io.*");
dojo.io.bind(bindArgs); 


thx for your help

jpotts
World-Class Innovator
World-Class Innovator
The web script framework has the capability for making remote calls to HTTP endpoints. It's essentially the "connector" object in Surf, if you're familiar with that. The cool thing is that because the web script framework in Surf is the same as the one in the repository, you can use the connector object from the repository tier. The last time I did this it was in 3.0 and the connector object had to be explicitly enabled on the repository tier. I don't know if that's still the case.

With the connector object enabled you can then do something like:
var connector = remote.connect("http");
var result = connector.call(someUrl);
if (result !== null) {
   var remoteResponse = new String(result);   
   var header = '<?xml version="1.0" encoding="UTF-8"?>';
   remoteResponse = remoteResponse.substring(header.length);
   var responseXml = new XML(remoteResponse);

This is the same approach you'd use for invoking remote endpoints over HTTP from web scripts running in the Surf tier.

Jeff