cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Actions in the web client

ale_carraro
Champ in-the-making
Champ in-the-making
Hi, I successfully followed the guide about writing custom Actions in the wiki (Custom_Action and Custom_Action_UI). The action runs fine from the "run action" action. I then read http://wiki.alfresco.com/wiki/Simple_Customisations#Adding_Custom_Menu_Items
about adding an entry in the menu, but I didn't understand how to run my custom action. Can someone help me on this please?
7 REPLIES 7

jey
Champ in-the-making
Champ in-the-making
I am also interested in this question !!!

In fact I succeeded to add a dialog in the menu but not a simple action …

If you want to do so here is a beginning of answer: an action extends ActionExecuterAbstractBase and is call through the method executeImpl, and a dialog extends BaseContentWizard and is call through the method finishImpl.

In order to add a dialog to the menu just follow the link…

But how can we add a simple action to this menu ??? GOOD QUESTION ?

ale_carraro
Champ in-the-making
Champ in-the-making

kevinr
Star Contributor
Star Contributor
As mentioned in the post linked in above, server actions are different to client "actions" and there is not a direct way to configure one in to the actions config in the client. It would be tricky anyway as most actions require arguments of some kind - most of which you would not be able to specify in config. However it can be done using the JavaScript API, the JavaScript API can create and execute server-side actions as it is capable of setting the required arguments to the action object. There are docs and example here:
http://wiki.alfresco.com/wiki/JavaScript_API#Actions_API

Once you have created your script that can launch your action, you can then configure in the script to your client action, the 'script' parameter for action config is discussed here:
http://wiki.alfresco.com/wiki/Externalised_Client_Actions

Hope this helps,

Kevin

jey
Champ in-the-making
Champ in-the-making
Thanks four your reply,

I'll try to build a javascript action to run my action…
First off all I'll read the article of the wiki that you mentioned 🙂

ale_carraro
Champ in-the-making
Champ in-the-making
Thank you very much!
I didn't understand that actions were different from client actions..

I put the following lines in the config:

   <config>
      <actions>
         <action id="sign_action">
            <label>Firma il documento</label>
            <image>/images/icons/FileActions_small.gif</image>
            <script>/Company Home/Data Dictionary/Scripts/_activate_action.js</script>
            <params>
               <param name="noderef">#{actionContext.nodeRef}</param>
            </params>
         </action>

         <!– Add action to more actions menu for each space –>
         <action-group id="document_browse">
            <action idref="sign_action" />
         </action-group>
      </actions>
   </config>
and in _activate_action.js script i have:

  // create sign action
  var sign= actions.create("sign-document");
  // execute action against a document   
  sign.execute(args["noderef"]);
However the last line throws the following exception:

org.alfresco.error.AlfrescoRuntimeException: Error during command servlet processing: Failed to execute script 'workspace://SpacesStore/67bd5012-1419-11dc-8819-698de64003c4': Can't find method org.alfresco.repo.jscript.ScriptAction.execute(string). (AlfrescoScript#4)
caused by:
org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/67bd5012-1419-11dc-8819-698de64003c4': Can't find method org.alfresco.repo.jscript.ScriptAction.execute(string). (AlfrescoScript#4)
caused by:
org.alfresco.error.AlfrescoRuntimeException: Can't find method org.alfresco.repo.jscript.ScriptAction.execute(string). (AlfrescoScript#4)
caused by:
org.mozilla.javascript.EvaluatorException: Can't find method org.alfresco.repo.jscript.ScriptAction.execute(string). (AlfrescoScript#4)

This seems an error in the javascript api rather than in my program (the action should run fine), any ideas? Thanks

kevinr
Star Contributor
Star Contributor
There's not an error in the JavaScript API - the issue is that the API deals with objects rather than simple NodeRef objects like the repository. You need to convert the noderef into a JavaScript Node object as that is what is expected by the execute() method - so the following should work:

  // create sign action
  var sign= actions.create("sign-document");
  // execute action against a document  
  sign.execute(search.findNode(args["noderef"]));

Thanks,

Kevin

ale_carraro
Champ in-the-making
Champ in-the-making
thank you very much! Now it works as expected