Steps to add a custom button/link in Document Actions and Folder Actions on Document and Folder Level:
Step 1: Create a directory scripts in ...\tomcat\shared\classes\alfresco\extension\
Step 2 :
cd into ...\tomcat\shared\classes\alfresco\extension\scripts
Create a file publishDoc.js
.....
document.copy(DestNode) - [write script according to your requirement]
.......
Step 3:
Registering action
Create a context file custom-action-services-context.xml in \tomcat\shared\classes\alfresco\extension\ with the following code :
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="publish-doc-action" parent="script">
<property name="scriptLocation">
<bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
<constructor-arg>
<value>alfresco/extension/scripts/publishDoc.js</value>
</constructor-arg>
</bean>
</property>
</bean>
</beans>
Step 4:
Calling action
Add the following code to tomcat\shared\classes\alfresco\web-extension\share-config-custom.xml:
<config evaluator="string-compare" condition="DocLibActions">
<!–
Action definitions
–>
<actions>
<!– Publish Document –>
<action id="publish-doc" icon="ic-publish" type="javascript" label="Publish">
<param name="function">onActionSimpleRepoAction</param>
<param name="action">publish-doc-action</param>
<param name="successMessage">Successfully Published</param>
<param name="failureMessage">failed</param>
</action>
</actions>
<actionGroups>
<!-- For action button to show up at document level -->
<actionGroup id="document-browse">
<action index="460" id="publish-doc"/>
</actionGroup>
<actionGroup id="document-details">
<action index="400" id="publish-doc"/>
</actionGroup>
<!-- For action button to show up at Folder level -->
<actionGroup id="folder-browse">
<action index="460" id="publish-doc"/>
</actionGroup>
<actionGroup id="folder-details">
<action index="400" id="publish-doc"/>
</actionGroup>
</actionGroups>
</config>
Step 5: Add icon image named ic-publish-16.png in tomcat\webapps\share\components\documentlibrary\actions\
Restart Alfresco server
You will be able to see a button in document Action and in Folder Action: