Incremental autonumeric
From OpenKM Documentation
For each new document creates a new unique autonumeric based on:
- 6 digits incremental id
- revision number starts with 1
- code is unique id + "-" + revision
To take it running it's needed register a property group and then create and automation task based on scripting.
Property group definition:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 2.1//EN"
"http://www.openkm.com/dtd/property-groups-2.1.dtd">
<property-groups>
<property-group label="Autonumeric" name="okg:autonumber">
<input label="Document ID" name="okp:autonumber.id" type="text" readonly="true"/>
<input label="Revision" name="okp:autonumber.revision" type="text" readonly="true"/>
<input label="Code" name="okp:autonumber.code" type="text" readonly="true"/>
</property-group>
</property-groups>
Scripting code:
import com.openkm.api.OKMPropertyGroup;
import com.openkm.api.OKMRepository;
import java.util.*;
import com.openkm.dao.DatabaseMetadataDAO;
String grpName = "okg:autonumber";
String table = "autonumber";
String sequenceName = "doc_id";
String path = OKMRepository.getInstance().getNodePath(null,uuid);
// Add Group
OKMPropertyGroup.getInstance().addGroup(null, path, grpName);
// Setting properties
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;
}
String revision = "1";
String code = id + "-" +revision;
Map map = new HashMap();
map.put("okp:autonumber.id",id);
map.put("okp:autonumber.revision",revision);
map.put("okp:autonumber.code",code);
OKMPropertyGroup.getInstance().setPropertiesSimple(null, path, grpName, map);
Example
Upload new document:
[[File:Okm_user_guide_332.png[[