Incremental autonumeric
From OpenKM Documentation
Create a unique autonumeric for each new document.
Description:
- There's a metadata with tree fields which stores data.
- Each time a new document is uploaded automation is executed. Automation script created a new unique autonumeric identifiers using metadata database sequence feature.
- Document id is a 6 digits incremental numeric
- 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
Register property group:
Create automation rule:
Upload new document: