• "Document create" pre-event automation actions

  • 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.
 #52219  by MohamadAli
 
Hi,

The problem I am trying to solve is the following:
  • I have a document named "document.docx"
  • user downloads this document, edits it, then uploads it, this is the base scenario
  • user downloads the same document again, now in windows, the document is renamed to "document (1).docx"
  • user edits it, uploads it, now it is considered as a new document so "document.docx" is not updated
What I want to do is create an automation action on pre-document created event, where I check the uploaded document name, remove the additional characters (1), (2), etc. and then in openkm this should have the same name as document, and therefore, it should update it (new version of the same document).

However, I cannot find enough info on pre-event variables, so I dont know how to do it.
May someone explain to me if what I want to do feasible, and how to do it (or some indicators)?

Thank you very much
 #52240  by jllort
 
For the best understanding take a look at the BaseDocumentModule where are filled the env variables to be sent to automation and later are recovered from the env map again.

From line 84 to line 96 ( special interest in line 88 and 94 in your case )
https://github.com/openkm/document-mana ... odule.java

In the automation env map, you will have a key with value AutomationUtils.DOCUMENT_NAME -> what you can get access from automation and if you want can replace by a new one.
 #52244  by MohamadAli
 
Thanks for your reply.

So my script for testing is now the following and it renames the document when its created in openkm
Code: Select all
import com.openkm.automation.AutomationUtils;

env.put(AutomationUtils.DOCUMENT_NAME, "test.docx");
However the problem now is that when the file already exists, I get error OKM-005003 because I am trying to create a document which exists instead of updating.

Is there a way to call update document from automation action and pass that document as an update?
I think I will use try {} catch {} and will update the file in catch {}.

Any ideas about that?
 #52250  by jllort
 
You must check if a document with that name already exists, if exist obviously will raise an error because we do not allow creating a document that already exist -> we allow only the edition. You should set a name policy that does not cause this kind of problem, like adding (1) how it does windows.

To check if a node exists you have the hasNode method in the OKMRepository class ( you must calculate the absolute openkm path of the new document and check if already exists or not ).
 #52281  by MohamadAli
 
thanks for you response.

Effectively, this is the behavior that I want: to update the document instead of creating a new one.

what I am thinking about it some method to intercept the "create new document" action and call "update document" action. Is this possible from automation or should I change source code?
 #52305  by jllort
 
Not necessary to change the code with current automation feature is enought. I suggest take a look at https://docs.openkm.com/kcenter/view/ok ... ction.html ( how to create a new plugin ) and also this internal class for a better understanding of what you will have in the environment variable https://github.com/openkm/document-mana ... e.java#L84

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.