• Scripting (start.bsh)

  • OpenKM has many interesting features, but requires some configuration process to show its full potential.
OpenKM has many interesting features, but requires some configuration process to show its full potential.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #11891  by olexandr
 
Hello,
I'm trying to create autostart script, which add automatically property groups.
But I don't understand how to use variables correctly, for example when I have start.bsh like:
Code: Select all
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.module.base.*;

String token = JcrSessionManager.getInstance().getSystemToken();
Session session = JcrSessionManager.getInstance().get(token);
String parent = com.openkm.util.FileUtils.getParent(eventNode.getPath());
I've got an error - eventNode variable not found.
How to correctly initialize this (and also these http://wiki.openkm.com/index.php/Script ... ables_used) variables?

Regards,
 #11928  by jllort
 
first try with
Code: Select all
String parent = com.openkm.util.FileUtils.getParent(eventNode.getPath());
System.out.println(parent);
 #11966  by pavila
 
The start.bsh script is executed when OpenKM starts (when JBoss starts) so there is no associated node nor event. If you want to do so, go to Administration > Repository view and put the scripting code in the desired folder.
 #12256  by olexandr
 
Thank you very much for making things clear!
I've enabled scripting for the folder and automatic example script is generated:
Code: Select all
print("UserId: "+session.getUserID());
print("EventType: "+eventType);
print("EventNode: "+eventNode.getPath());
print("ScriptNode: "+scriptNode.getPath());
As far as I understand this should print user node info, when I enter the folder, but nothing happens. Should it print somewhere on the screen or somewhere in the logs?

Sorry for my questions - for me http://wiki.openkm.com/index.php/Scripting is a bit condensed.
 #12296  by jllort
 
You must take a look at server.log ( tail -f server.log on linux ) or open with some windows editor ( gedit, ultraedit or similar )
 #12311  by pavila
 
Scripting can be set by folder or document. You need to go to Administration > Repository view and browse the repository at low level. Be careful because and error can damage the document repository! When you have located the right place, select Scripting: Set script and a new scripting property will be added to the node. This property can be edited to set your custom code.
 #12553  by olexandr
 
Hello, thank you for the replies!

But still it doesn't print anything neither in server.log, nor start.log...

I created folder Test, added "Set script" with a default one - then I go to that folder - but nothing is shown in the server.log. Which action should actually call the script? When user access the folder?
 #12570  by olexandr
 
I've found my error!

The script is run not when I access the folder, but when I upload document.

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.