cancel
Showing results for 
Search instead for 
Did you mean: 

Creating an ui action to launch a js script

vbaudry
Champ in-the-making
Champ in-the-making
Hello !

I would like to create an ui action tu launch a determined js script.

Does anyone know how I can do that quite simply ?

I've seen how to create a custom ui button, but how can I do a really simple actionlistener that only launch the script ?
6 REPLIES 6

kevinr
Star Contributor
Star Contributor
We have added support for this in 1.4, you can now specify a script directly in the XML definition for an action. In your override file for the action definition XML, you just need a line like this as part of your action definition:


<script>/Company Home/Data Dictionary/Scripts/myjavascript.js</script>

You can also specify the full NodeRef to the script, but the path is normally easier.

Thanks,

Kevin

vbaudry
Champ in-the-making
Champ in-the-making
Thanks a lot ! I tested it in 1.4 preview and it seems to work.

But I've a little problem with de javascript.

My file is really simple, it looks like this :

// modify the parent space name
space.name = space.name + " 1";
space.save();

But when I run my action, an error says that "space" is not defined.

Any idea ?

vbaudry
Champ in-the-making
Champ in-the-making
Got another point.

When I execute the script, it runs in the window and replaces alfresco. Is it possible to come back to alfresco after the script has run ?

kevinr
Star Contributor
Star Contributor
Yes the script command servlet excepts a URL parameter called "return-page" that defines the return page URL e.g.

http://localhost:8080/alfresco/command/script/execute?scriptPath=/Company%20Home/Data%20Dictionary/S...

Thanks,

Kevin

calexo
Champ in-the-making
Champ in-the-making
// modify the parent space name
space.name = space.name + " 1";
space.save();But when I run my action, an error says that "space" is not defined.
Any idea ?
Hi !
I'm having the same problem, while using a JS script to change a document property : it says document is unknown…
Here is the action, as I defined :
<action id="payer">
         <label>Payer</label>
         <image>/images/icons/add.gif</image>
         <label>Payer</label>
         <script>/Company Home/Data Dictionary/Scripts/PayerFacture.js</script>
         <params>
               <param name="id">#{document.id}</param>
         </params>
      </action>

kevinr
Star Contributor
Star Contributor
That's a completely different issue. You cannot enter script into the <params> tag for the action definition. e.g. this is wrong:

<params>
<param name="id">#{document.id}</param>
</params>


All that section does is pass URL parameters to your script as specified in the <script> element.

The params section should read:

<params>
<param name="id">#{actionContext.id}</param>
</params>

Thanks,

Kevin