• Script to get document name

  • He we will discuss about how to make customization and improvement to the OpenKM source code.
He we will discuss about how to make customization and improvement to the OpenKM source code.
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.
 #45919  by jorseng
 
Hi,

I am trying to append the file name based on the metadata value.
The code below is meant to be run in the automation action "execute script"
Code: Select all
import com.openkm.api.OKMPropertyGroup;
import com.openkm.api.OKMRepository;
import com.openkm.api.OKMDocument;
import java.util.*;
import com.openkm.bean.form.*;
import com.openkm.bean.Document;

String grpName = "okg:medicalrecord";
String path = OKMRepository.getInstance().getNodePath(null,uuid);

boolean merge;

for (FormElement formElement : OKMPropertyGroup.getInstance().getProperties(null,path,grpName)) {
	if (formElement.getName().equals("okp:medicalrecord.merge")) {
		merge = formElement.getValue();
			
			if (merge==true) {
				docName = OKMDocument.getInstance().getProperties(null,path).getTitle();
				String newName = docName + " Merge!";
				OKMDocument.getInstance().rename(null,path,newName);
				
				//search for file with the same name, mrn,
				//then merge pdf, inherit metadata
				//condition to check - both have no metadata, one has, both have
			}
			
	}
}

However looking through the API i cannot seem to find the right method to get the file name and append the name with a "Merge!" at the end of the file name.
 #45921  by lnovoa
 
Hi!,
you have to add this line to get the name of the path

String name = path.substring(path.lastIndexOf('/') + 1);

For example:
path: /okm:root/documentName.pdf
The result be: documentName.pdf
 #45931  by jllort
 
Also exists a class PathUtils with method getName.
 #45941  by jorseng
 
Dear jllort,

Thanks for your prompt reply! I mange to get it working, however each time the script renames it, i get the error message below.
error message.PNG
error message.PNG (32.9 KiB) Viewed 13481 times
Here is my workflow configuration:
automation prompt.PNG
automation prompt.PNG (6.73 KiB) Viewed 13481 times
Here is the action:
automation action.png
automation action.png (35.42 KiB) Viewed 13481 times
Anyway i can avoid getting the error message each time the script runs?
 #45947  by lnovoa
 
The file is renaming it without the extension.
The PathUtils and FileUtils classes contain methods to obtain the extension.
 #45963  by jllort
 
I think it is caused by OpenKM bug, basically you apply metadata change to document XXXX.pdf and come back as YYYY.pdf, but the UI is trying to refresh YYYY.pdf. In the UI should evaluate if the document name has been changed before trying to refresh previous path ( what has been changed ). This was an old bug from professional version what I suspect has not been corrected in community.

Add an issue here https://github.com/openkm/document-mana ... tem/issues
 #46030  by jorseng
 
Dear Inovoa,
I have tried adding extension to the renaming, the error remained.

Dear jllort,
I will post the issue at the given link.

Thank you all!

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.