• Troubles renaming document whit autoincrement id and metadata

  • 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.
 #43415  by really.neo
 
Hi, I am user of OPEN KM Community Version 6.3.3 build: 8289.

I have troubles renaming the document, I am using this automate rules and script, based on your excellent wiki information, and It's actually working adding metadata whit form the wizard, and id autoincrement, but the rename action is not working :(.

property group registration:
Code: Select all
</property-group>
    
     <property-group label="Datos" name="okg:data">
		<input label="Id" type="text" name="okp:data.id" width="200px" readonly="true"/>
		<input label="Oficio No" type="text" name="okp:data.project.code" width="200px">
			<validator type="req"/>
			<validator type="maxlen" parameter="10"/>
			<validator type="minlen" parameter="3"/>
		</input>
		<input label="Asunto" type="text" name="okp:data.description" width="200px">
			<validator type="req"/>
			<validator type="maxlen" parameter="150"/>
		</input>
  </property-group>

Screenshot:
imagegroup.jpg
imagegroup.jpg (63.56 KiB) Viewed 20419 times
Automation information:

document creation and set property group
documentcreation,setpropertygroup.jpg
documentcreation,setpropertygroup.jpg (25.3 KiB) Viewed 20419 times
Document creation, validation and actions

ExecuteScripting info:
Code: Select all
import com.openkm.api.OKMPropertyGroup;
import com.openkm.api.OKMRepository;
import java.util.*;
import com.openkm.dao.DatabaseMetadataDAO;
 
String grpName = "okg:data";
String table = "autonumber";
String sequenceName = "doc_id";
String path = OKMRepository.getInstance().getNodePath(null,uuid);
 
// Add Group
OKMPropertyGroup.getInstance().addGroup(null, path, grpName);

String id = String.valueOf(DatabaseMetadataDAO.getNextSequenceValue(table, sequenceName));
 
switch (id.length()) {
    case 1:
    	id = "00000" + id;
    	break;
    case 2:
    	id = "0000" + id;
    	break;
    case 3:
    	id = "000" + id;
    	break;
    case 4:
    	id = "00" + id;
    	break;
    case 5:
    	id = "0" + id;
    	break;
    }

    Map map = new HashMap();
    map.put("okp:data.id",id);
    OKMPropertyGroup.getInstance().setPropertiesSimple(null, path, grpName, map);
}
documentcreationvalidationactions.jpg
documentcreationvalidationactions.jpg (56.94 KiB) Viewed 20419 times

Set property group, validation and actions
setpropertygroupvalidationactions.jpg
setpropertygroupvalidationactions.jpg (51.32 KiB) Viewed 20419 times
ExecuteScripting info:
Code: Select all
import com.openkm.api.OKMPropertyGroup;
import com.openkm.api.OKMRepository;
import java.util.*;
import com.openkm.dao.DatabaseMetadataDAO;
import com.openkm.api.OKMPropertyGroup;
import com.openkm.bean.form.FormElement;
import com.openkm.bean.form.Input;
import com.openkm.bean.form.Select;
import com.openkm.bean.form.Option;
import com.openkm.util.PathUtils;
import com.openkm.util.FileUtils;
import com.openkm.api.OKMDocument;
 
String grpName = "okg:data";
String table = "autonumber";
String sequenceName = "doc_id";
String path = OKMRepository.getInstance().getNodePath(null,uuid);
 
// Evaluate if already has property group
boolean add = true;
String prjCode = "";
String id = "";
String desc = "";
for (FormElement formElement : OKMPropertyGroup.getInstance().getProperties(null, path, grpName)) {
    if (formElement.getName().equals("okp:data.id")) {
        docId = ((Input) formElement).getValue();
        add = id.equals("");
    } else if (formElement.getName().equals("okp:data.project.code")) {
        prjCode = ((Input) formElement).getValue();
    } else if (formElement.getName().equals("okp:data.description")) {
        desc = ((Input) formElement).getValue();
            }
        }  
 
// Setting properties
if (add) {
    OKMPropertyGroup.getInstance().setPropertiesSimple(null, path, grpName, map);
}
 
// rename document
String newName = id + "-" + prjCode + "-" + desc + "." + FileUtils.getFileExtension(PathUtils.getName(path));
OKMDocument.getInstance().rename(null, path, newName);

Then, here is the example working, auto increment Id, and setting metadata whit wizard form. but the rename script is not working, thank you for your help.
workingmetadataidautonotrenaming.jpg
workingmetadataidautonotrenaming.jpg (82.35 KiB) Viewed 20419 times
 #43429  by jllort
 
The second script I think is wrong.

You shold validate if the document what has fired the event setProperties has the property group:
Code: Select all
if (OKMProperty.getInstance().hasGroup(null, "okg:XXXX") {
  // Here execute the rename
}
I suggest using classes rather scripting, because you are not able to debug scripting but is quite easy debug action classes. I suggest take a look here: https://docs.openkm.com/kcenter/view/ok ... ction.html
 #43454  by really.neo
 
jllort wrote:The second script I think is wrong.

You shold validate if the document what has fired the event setProperties has the property group:
Code: Select all
if (OKMProperty.getInstance().hasGroup(null, "okg:XXXX") {
  // Here execute the rename
}
I suggest using classes rather scripting, because you are not able to debug scripting but is quite easy debug action classes. I suggest take a look here: https://docs.openkm.com/kcenter/view/ok ... ction.html
Thank you very much for your answer, I modified the metadata wizard form and the script like this, the metadata set is working right, but the rename is not working yet. It's like this:

Code: Select all
import com.openkm.api.OKMPropertyGroup;
import com.openkm.api.OKMRepository;
import java.util.*;
import com.openkm.dao.DatabaseMetadataDAO;
import com.openkm.api.OKMPropertyGroup;
import com.openkm.bean.form.FormElement;
import com.openkm.bean.form.Input;
import com.openkm.bean.form.Select;
import com.openkm.bean.form.Option;
import com.openkm.util.PathUtils;
import com.openkm.util.FileUtils;
import com.openkm.api.OKMDocument;
 
String grpName = "okg:data";
String table = "autonumber";
String sequenceName = "doc_id";
String path = OKMRepository.getInstance().getNodePath(null,uuid);
 
// Evaluate if already has property group
boolean add = true;
String prjCode = "";
String id = "";
String desc = "";
String LetraID = "";
String year = "";
for (FormElement formElement : OKMPropertyGroup.getInstance().getProperties(null, path, grpName)) {
    if (formElement.getName().equals("okp:data.id")) {
        docId = ((Input) formElement).getValue();
        add = id.equals("");
    } else if (formElement.getName().equals("okp:data.project.code")) {
        prjCode = ((Input) formElement).getValue();
    } else if (formElement.getName().equals("okp:data.description")) {
        desc = ((Input) formElement).getValue();
    } else if (formElement.getName().equals("okp:data.letra")) {
        LetraID = ((Input) formElement).getValue();
    }  else if (formElement.getName().equals("okp:data.year")) {
        year = ((Input) formElement).getValue();
    }
}
 
// Setting properties
if (add) {
    OKMPropertyGroup.getInstance().setPropertiesSimple(null, path, grpName, map);
}
 
// rename document
if (OKMProperty.getInstance().hasGroup(null, "okg:data") {
String newName = id + "-" + LetraID + "-" + year + "-" + prjCode + "-" + desc + "." + FileUtils.getFileExtension(PathUtils.getName(path));
OKMDocument.getInstance().rename(null, path, newName);
}
Adding at the end:
Code: Select all
if (OKMProperty.getInstance().hasGroup(null, "okg:data") {
String newName = id + "-" + LetraID + "-" + year + "-" + prjCode + "-" + desc + "." + FileUtils.getFileExtension(PathUtils.getName(path));
OKMDocument.getInstance().rename(null, path, newName);
}
foroejemplorenme.png
foroejemplorenme.png (38.08 KiB) Viewed 20409 times
The file upload right but still dont rename, I dont know anything else to try, Thank your for your help.

OPEN KM Community Version 6.3.3 build: 8289.

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.