• setting Lock during Document Create not working in script

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
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.
 #12964  by ngovinda
 
I would like to set all documents to "Lock" setting when users upload a document.

So I created a script at the respective folder where I use the following lines:
Code: Select all
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.module.base.*;
import com.openkm.bean.Document;


if (eventType.equals("CREATE_DOCUMENT")) {
        String token = JcrSessionManager.getInstance().getSystemToken();
        Session session = JcrSessionManager.getInstance().get(token);
        Node rootNode = session.getRootNode().getNode(Repository.ROOT);
        String docName = com.openkm.util.FileUtils.getName(eventNode.getPath());
       String parentDir = com.openkm.util.FileUtils.getParent(eventNode.getPath());
        Node myNode = session.getNode(parentDir + "/" + docName);
 
        Document doc = BaseDocumentModule.getProperties(session, myNode);
        doc.setLocked(true);
        myNode.setProperty(Document.NAME, "Name1.xls");

         String[] keywords = {"one", "two"};
         myNode.setProperty(Property.KEYWORDS, keywords);
        myNode.save();
        rootNode.save();
}

The Document Name change works and the Keywords work,

BUT the doc.setLocked(true); does not work.

Why is this? and How can I set Locked to true by default when uploading documents?

Thanks in advance - Govinda
 #12980  by jllort
 
The problem is that you're changing a property of object document, that has no relevance. Really you should execute lock method ( I suggest take a look at DocumentServlet.java ), you must execute something like :
Code: Select all
OKMDocument.getInstance().lock(null, docPath);

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.