Incremental autonumeric

From OpenKM Documentation
Revision as of 17:29, 7 January 2013 by Pavila (talk | contribs)

Jump to: navigation, search

Create a unique autonumeric for each new document.


  • 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"
    <property-group label="Autonumeric" name="okg:autonumber">
        <input label="Document ID" name="" 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"/>

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;
    case 2:
    	id = "0000" + id;
    case 3:
    	id = "000" + id;
    case 4:
    	id = "00" + id;
    case 5:
    	id = "0" + id;

String revision = "1";
String code = id + "-" +revision;

Map map = new HashMap();
OKMPropertyGroup.getInstance().setPropertiesSimple(null, path, grpName, map);


Register property group: Okm user guide 328.png

Create automation rule: Okm user guide 329.png

Okm user guide 330.png

Okm user guide 331.png

Upload new document:

Okm user guide 332.png