Search the FirstSpirit Knowledge Base
Hello developers,
When do you write a script, and when do you write a module running on the server? I have written several long scripts and I am beginning to think they should be modules on the server instead. I'm expecting that modules written in Java will run faster than Beanshell scripts. I think it would also be easier to write good object-orientated code in Java, with the support of an IDE like Eclipse or IntelliJ.
If I do start doing this - how do I call my module from an FS_BUTTON? How are parameters passed down? Is context.getElement() the same in web client as it is on the server? Can a module interact with the web client, for instance triggering a navigation from one page to another?
I have attached a sample script that I'm thinking of moving to a server on the module.
It creates a copy of an existing page, and updates various links and form elements on both the original and new page.
I know this is a vague subject - I was just hoping for some ideas and inspiration!
With thanks,
Liam Davison
Hello Liam,
do you need further help or did Michael's reply already help you? If so, it would be great if you marked his reply as "correct answer" so that other community users find the solution easily.
Best regards,
Sebastian
Hello Liam,
the type (module or script) has nothing to do with the location where the code is executed. Both script and module code can be executed in the client or on the server. It only depends on the context - i.e. how and where the start is triggered. Despite modules are always installed on the server, the client can load them from there and execute the code locally.
In general, we strongly recommend modules instead of beanshell scripts for multiple reasons:
Technically you don't "execute a module" but more precisely one of the module's components. One common component type is a class implementing the Executable interface and declared as <public> component. Such Executables can then be used in FS_BUTTONs. The Executable interface defines an "execute" method you will have to implement. Here, you get a parameter map of type Map<String, Object>. You can acces the context object using the key "context" from that Map.
In some cases (e.g. workflow scripts, (context) menu scripts) you need a "script object". But this can directly delegate to an Executable in a module. Such a script contains only two lines:
#!executable-class
NameOfTheExecutablesPublicComponent
For more information, you should have a look at the plugin development topics in the ODFS and especialy the examples.
Michael
Hello Liam,
do you need further help or did Michael's reply already help you? If so, it would be great if you marked his reply as "correct answer" so that other community users find the solution easily.
Best regards,
Sebastian