Create Javascript actions in Alfresco

Actions available in Alfresco is an important part of Alfresco user interface because using those actions a user can manipulate content. Every now and then we come across requirements of creating new actions on the Alfresco interface. I had previously written two posts related to Actions in Alfresco share.

In this post I am going to explain how to create Alfresco javascript based action.

Step 1:

Add action entry in share-config-custom.xml

  <action id="folder-run-report" type="javascript" label="">
            <param name="function">runReport</param>
               <permission allow="true">Write</permission>

Another entry will be to include that action in action group.


    <actionGroup id="folder-browse">          
            <action index="140" id="folder-run-report" />

Step 2:

Create action handler in javascript file(custom-action.js)."registerAction", {
	actionName: "runReport",
	fn: function _anyFunction(selectedNodes) {
		var nodesToSubmit = [];
		if (selectedNodes.nodeRef != undefined) {
		} else if (selectedNodes.length != undefined) {
			for (var i = 0; i < selectedNodes.length; i++) {
		} else {
			success: {
				message: this.msg("message.runReport.success", selectedNodes.displayName)
			failure: {
				message: this.msg("message.runReport.failure", selectedNodes.displayName)
			webscript: {
				name: "sample/reportWebscript",
				method: Alfresco.util.Ajax.POST
			config: {
				requestContentType: Alfresco.util.Ajax.JSON,
				dataObj: {
					nodeRefs: nodesToSubmit

Above function will be called whenever user client on “runReport” action from alfresco share.I am calling repository webscript(sample/reportWebscript) from that function which will do all manipulation of content. Reason for calling that repository script is this is client side script and you will not have access to repository services to you need to go through this approach.

Step 3:

Register javascript file with Alfresco share using following entry in share-config-custom.xml

<config evaluator="string-compare" condition="DocLibCustom" replace="true">
         <js src="/components/documentlibrary/custom-action.js" />

Just place all those files in appropriate folder structure generate amp file. Deploy everything in Alfresco and restart the server you should be able to see new action. You will have to implement related repository webscript as I have leave it to you.

Looking for quality Alfresco Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , | Posted under Alfresco | RSS 2.0

Author Spotlight


I love opensource technologies working with those technologies from the time I have stepped in to the Software Industry. Alfresco CMS is my area of expertise. I have worked on various complex implementations which involved integration of Alfresco with other technologies, extensively worked with JBPM workflows and Webscripts.

Leave a Reply

Your email address will not be published. Required fields are marked *