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