Custom Javascript action is not executed

cancel
Showing results for 
Search instead for 
Did you mean: 
qwertz
Active Member II

Custom Javascript action is not executed

Jump to solution

Hey guys!

I want that some javascript code is executed on the client side through a custom action. To gain some knowledge about this I went through the official documentation and tried the tutorial: Adding new actions to the Document Library | Alfresco Documentation. I am using the alfresco sdk 3 and need to generate a jar file instead of an AMP, so the file paths in the documentation are different from mine (at least as far as I know, I am new to all of this).

Where exactly do I need to put my custom javascript file? For now I have put it to src\main\resources\META-INF\resources\components\documentlibrary. In this directory I've also put a directory action/ where the icons for the custom share action are located. The problem is: I can see the custom action and even the icon in share but when I click on it, nothing happens. I assume I've used the wrong directory for the javascript file.

add-doclib-actions-extension-modules.xml:

<extension>
    <modules>
        <module>
            <id>Call Webscript</id>
            <version>1.0</version>
            <auto-deploy>true</auto-deploy>
            <configurations>
                <config evaluator="string-compare" condition="DocLibActions">
                    <actions>
                        <action id="alfresco.tutorials.doclib.action.callWebScript"
                                icon="callws"
                                type="javascript"
                                label="alfresco.tutorials.doclib.action.callWebScript.label">

                            <param name="function">onActionCallWebScript</param>
                            <param name="successMessage">alfresco.tutorials.doclib.action.callWebScript.msg.success</param>
                            <param name="failureMessage">alfresco.tutorials.doclib.action.callWebScript.msg.failure</param>
                        </action>
                              <action id="alfresco.tutorials.doclib.action.showCustomMessage"
                                icon="showmsg"
                                type="javascript"
                                label="alfresco.tutorials.doclib.action.showCustomMessage.label">

                            <param name="function">onShowCustomMessage</param>
                              </action>
                    </actions>
                         <actionGroups>
                              <actionGroup id="document-browse">
                                    <action index="400" id="alfresco.tutorials.doclib.action.callWebScript" />
                                    <action index="401" id="alfresco.tutorials.doclib.action.showCustomMessage" />
                              </actionGroup>
                              <actionGroup id="document-details">
                                   <action index="400" id="alfresco.tutorials.doclib.action.callWebScript" />
                                   <action index="401" id="alfresco.tutorials.doclib.action.showCustomMessage" />
                              </actionGroup>
                         </actionGroups>
                </config>
            </configurations>
        </module>
    </modules>
</extension>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

custom-doclib-actions.js:

YAHOO.Bubbling.fire("registerAction",
     {
          actionName: "onShowCustomMessage",
          fn: function org_alfresco_training_onShowCustomMessage(file) {
               Alfresco.util.PopupManager.displayMessage(
                    {
                         text: this.msg("alfresco.tutorials.doclib.action.showCustomMessage.text",
                              file.displayName, Alfresco.constants.USERNAME)
                    });
          }
     });
    
    YAHOO.Bubbling.fire("registerAction",
        {
            actionName: "onActionCallWebScript",
            fn: function org_alfresco_training_onActionCallWebScript(file) {
                    console.log("js called");
                this.modules.actions.genericAction(
                    {

                        success: {
                            callback: {
                                fn: function org_alfresco_training_onActionCallWebScriptSuccess(response) {
                                    Alfresco.util.PopupManager.displayPrompt(
                                        {
                                            title: this.msg("alfresco.tutorials.doclib.action.callWebScript.msg.success"),
                                            text: JSON.stringify(response.json),
                                            buttons: [
                                                {
                                                    text: this.msg("button.ok"),
                                                    handler: function org_alfresco_training_onActionCallWebScriptSuccess_success_ok() {
                                                        this.destroy();
                                                    },
                                                    isDefault: true
                                                },
                                                {
                                                    text: this.msg("button.cancel"),
                                                    handler: function org_alfresco_training_onActionCallWebScriptSuccess_cancel() {
                                                        this.destroy();
                                                    }
                                                }]
                                        });

                                },
                                scope: this
                            }
                        },
                        failure: {
                            message: this.msg("alfresco.tutorials.doclib.action.callWebScript.msg.failure",
                                file.displayName, Alfresco.constants.USERNAME)
                        },
                        webscript: {
                            name: "sample/fileinfo?nodeRef={nodeRef}",
                            stem: Alfresco.constants.PROXY_URI,
                            method: Alfresco.util.Ajax.GET,
                            params: {
                                nodeRef: file.nodeRef
                            }
                        },
                        config: {}
                    });
            }
        });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I've tried enclosing custom-doclib-actions.js with

(function () { /* code from above */  })();

but that didn't work either (I've read in some post that removing this enclosure solves the problem).

I would appreciate it a lot if someone had any tips for me.

1 Solution

Accepted Solutions
afaust
Master

Re: Custom Javascript action is not executed

Jump to solution

Have you even included your custom file as a dependency so that it is loaded at runtime? The documentation you referenced is missing that important detail, though it is contained in another section of the same dev extension chapter. As you can see from "Adding new metadata templates" you need to add a section for "CustomDoclib" to load your custom JavaScript file.

View solution in original post

2 Replies
afaust
Master

Re: Custom Javascript action is not executed

Jump to solution

Have you even included your custom file as a dependency so that it is loaded at runtime? The documentation you referenced is missing that important detail, though it is contained in another section of the same dev extension chapter. As you can see from "Adding new metadata templates" you need to add a section for "CustomDoclib" to load your custom JavaScript file.

qwertz
Active Member II

Re: Custom Javascript action is not executed

Jump to solution

That was the solution, thanks a lot!