cancel
Showing results for 
Search instead for 
Did you mean: 

Register a javascript custom action

scouil
Star Contributor
Star Contributor
Hello,

I'm trying to register a Javascript action for it to be accessible in javascript (actions.create("myAction") ).
Unfortunately, just dropping the file in Data Dictionnary/Scripts/ just doesn't do it.

For java backed actions it's quite straightforward:

<bean id="…" class="path.to.my.JavaClass" parent="action-executer">
    …….
</bean>
but I can't find a way to register a js file as an action. Be it from alfresco or from the filesystem.
5 REPLIES 5

jpotts
World-Class Innovator
World-Class Innovator
You can write a behavior that is implemented in JavaScript and then wire that up through a Spring bean. But I do not think that rule actions can be implemented in JavaScript, except indirectly by invoking the "script" action.

When you use the script action, one of the parameters ("script-ref") is the nodeRef of the script you want to run.

So you can put your script anywhere you want (Data Dictionary/scripts is a good choice) and then within your JavaScript you can do a search to find it and get its nodeRef, then set up and run the "script" action, passing the nodeRef of the script you want to run as a parameter and the node you are running the action against as the argument to the execute call.

Jeff

scouil
Star Contributor
Star Contributor
Thanks for your lead Jeff.

The script action was indeed the way to go.
I created my own action extending the script action and pre-parametered with my script.
Since there's no setter for the nodeRef I used the scriptLocation attribute instead.

If anyone is interested, here's the code:

<bean id="my-script-action" parent="script">
    <property name="scriptLocation">
        <bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
            <constructor-arg>
                <value>alfresco/extension/scripts/my-script.js</value>
            </constructor-arg>
        </bean>
    </property>
</bean>

akash066
Champ in-the-making
Champ in-the-making
Hi,

Can i know where this bean file is present and which bean file i need to modify for this to work ?


Any help would be appreciated.



With cheers,
Akash

jpotts
World-Class Innovator
World-Class Innovator
You can place that XML in your own custom Spring bean config file and Alfresco will pick it up as long as its name ends in "context.xml" and is on the classpath. Typically, custom Spring config files reside in either $TOMCAT_HOME/webapps/alfresco/WEB-INF/classes/alfresco/extension or $TOMCAT_HOME/shared/classes/alfresco/extension.

Jeff

akash066
Champ in-the-making
Champ in-the-making
Thanks for the help Jeff.

There is another thing i wanted to know, that if i want to run my custom-script file as a rule then how to configure it in rule-config files. What i want to say is that if i create a customized javascript file then how can i deploy it and where to deploy it.



Akash