cancel
Showing results for 
Search instead for 
Did you mean: 

Create a repo action in javascript

kavilash23
Champ on-the-rise
Champ on-the-rise
Hi Guys,

I know we can implement a repo action in java by extending ActionExecuterAbstractBase and use its bean id in share.

But is there a way to implement the repo action in javascript?

Thanks,

Kavi
3 REPLIES 3

cgiuliano
Champ in-the-making
Champ in-the-making
Hello Kavi,

Sure you can: it's enough you can use the ExecuteScript out-of-the-box action to run whatever JavaScript on repository tier.
The ExecuteScript is already available as a rule or you can add it as an action in Share's document library, just customizing the share-config.xml file (in that case please have a look at the action with id "document-execute-script" in the default share-documentlibrary-config.xml file).
If you upload your JavaScript into the repository, in Data Dictionary/Scripts, it will be immediately available.

Hope this is the answer you were looking for.
Regards,
Carlo

Thanks for the response Carlo.

Not exactly what I was after. Because if you look at the itemId  part for "document-execute-script" action in share-documentlibrary-config.xml you would see "script" is written which is a spring bean id hence the actual job is being done in java class.

cgiuliano
Champ in-the-making
Champ in-the-making
Hi Kavi,

Actually I haven't tried to use the execute-script action to run a script programmatically, just used it in interactive mode.
Though I'm currently using the same mechanism through several rules, where I run a set of JavaScripts successfully.

If your requirement is to actually add a new action to the document library menu, I do believe you can work on a customization of the document-execute-script action. Some clues that might help you:
- the document-execute-script is implemented by onActionFormDialog;
- the above just configures and executes a call to Alfresco.util.PopupManager.displayForm to display the available scripts (JavaScripts!), stored in the Data Dictionary\Scripts container;
- the form processor web script (api/action/script/formprocessor) process the request by saving a "virtual" object of type action/script (itemKind "action" and itemId "script"), through a call to formService.saveForm;
- the latter call actually launches the JavaScript you have chosen.
If you try it manually, it works. In order to run it programmatically, you might call the form processor with the needed argumets to save an action script, as it does in the default behaviour. I'm afraid I'm not able to give you further details on the core mechanism, managed (I suppose) by the FormServiceImpl Java class (package org.alfresco.repo.forms).

Hope this helps.

Regards,
Carlo