Skip to content

OKMRecord

In most methods you’ll see a parameter named “recId”. The value of this parameter can be a valid record UUID.

Also, in all methods you’ll see a parameter named “token”. Because Cron Tasks are executed in the background without authentication, the methods used in this scenario might use the token parameter. In the default application execution context, you must use the “null” value, which indicates the application must use the “user session”.

Description:

Method Return values Description
create(String token, Record rec) Record Creates a new record and returns a Record object.
  • The variable path in the parameter rec must be initialized. It indicates the folder path in OpenKM.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
Record rec = new Record();
rec.setPath("/okm:root/test");
Record newRec = okmRecord.create(null, rec);
System.out.println(newRec);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createWithPropertyGroup(String token, Record rec, String grpName, Map<String, String> properties) Record Same as create(), but also sets a metadata group’s properties on the record in the same call, instead of a create() followed by a separate OKMPropertyGroup.addGroup() call.
  • The variable path in the parameter rec must be initialized, same as create(). The grpName should be a valid Metadata group name, and only the properties belonging to that group are applied - any other keys present in the properties map are ignored.

Example:

package com.openkm;
import java.util.HashMap;
import java.util.Map;
import com.openkm.api.OKMRecord;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
Record rec = new Record();
rec.setPath("/okm:root/test");
Map<String, String> properties = new HashMap<>();
properties.put("okp:invoice.number", "INV-000");
// Create record with metadata in a single atomic call
Record newRec = okmRecord.createWithPropertyGroup(null, rec, "okg:invoice", properties);
System.out.println(newRec);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createSimple(String token, String recPath) Record Creates a new record and returns a Record object.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
String recPath = "/okm:root/PKI-100200";
Record newRec = okmRecord.createSimple(null, recPath);
System.out.println(newRec);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getProperties(String token, String recId) Record Returns the record properties.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
Record rec = okmRecord.getProperties(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
System.out.println(rec);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
delete(String token, String recId) void Deletes a record.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
okmRecord.delete(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
purge(String token, String recId) void The record is permanently removed from the repository.
  • Usually you will purge folders in /okm:trash/userId - the personal user trash locations - but it is possible to directly purge any record from the repository.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
okmRecord.purge(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
rename(String token, String recId, String newName) Record Renames a record.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
Record renamedRec = okmRecord.rename(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "newname");
System.out.println(renamedRec);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
move(String token, String recId, String dstId) void Moves a record into a folder or another record.
  • The value of the dstId parameter should be a folder or record UUID.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
okmRecord.move(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "b6848ac2-345f-454e-964a-eba4dcc020e6");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
copy(String token, String recId, String dstId) Record Copies a record into a folder or record and returns the new Record object.
  • The value of the dstId parameter should be a folder or record UUID.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
Record newRec = okmRecord.copy(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "b6848ac2-345f-454e-964a-eba4dcc020e6");
System.out.println(newRec);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
copy(String token, String recId, String dstId, String newName) Record Copies a record into a folder or record and returns the new Record object.
  • The value of the dstId parameter should be a folder or record UUID.
  • When the newName parameter is null, the record will retain the same name.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
Record newRec = okmRecord.copy(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "b6848ac2-345f-454e-964a-eba4dcc020e6", "newname");
System.out.println(newRec);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
extendedCopy(String token, String recId, String dstId, String newName, ExtendedAttributes extAttr) Record Copies a record with associated data into a folder or record and returns the new Record object.
  • The value of the dstId parameter should be a folder or record UUID.
  • When the newName parameter is null, the record will retain the same name.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.bean.ExtendedAttributes;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
ExtendedAttributes extAttr = new ExtendedAttributes();
extAttr.setKeywords(true);
extAttr.setCategories(true);
extAttr.setNotes(true);
Record newRec = okmRecord.extendedCopy(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474", "PKI-100201", extAttr);
System.out.println(newRec);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
isValid(String token, String recId) boolean Returns a boolean that indicates whether the node is a record.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
boolean valid = okmRecord.isValid(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
System.out.println(valid);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getPath(String token, String recId) String Converts a record UUID to its repository path.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
String path = okmRecord.getPath(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
System.out.println(path);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getChildren(String token, String fldId) List Returns a list of all records whose parent is fldId.
  • The parameter fldId can be a folder or a record node.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
for (Record rec : okmRecord.getChildren(null, "b6848ac2-345f-454e-964a-eba4dcc020e6")) {
System.out.println(rec);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
lock(String token, String recId) LockInfo Locks a record and returns an object with the lock information.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
okmRecord.lock(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
unlock(String token, String recId) LockInfo Unlocks a locked record.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
okmRecord.unlock(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
forceUnlock(String token, String recId) void Unlocks a locked record.
  • This method allows unlocking any locked record.
  • It is not necessary for the same user who performed the original checkout lock action to perform this action.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
okmRecord.forceUnlock(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
setTitle(String token, String recId, String title) void Sets a record’s title.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
okmRecord.setTitle(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "new title");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
setNodeClass(String token, String recId, long ncId) void Sets the NodeClass.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
long ncId = 2;
okmRecord.setNodeClass(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", ncId);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
setDispositionStage(String token, String recId, long stage) void Sets the disposition stage

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
long stage = 1;
okmRecord.setDispositionStage(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", stage);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
addNodeClassChildren(String token, String recId, long ncId) void Adds the NodeClass of the record to the parent folders.
  • Used for navigation purposes to determine when a folder contains a node of this node class.
  • The method propagates the node class value to the parent containers (folders) to indicate that there is a node of this type.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
long ncId = 2;
okmRecord.addNodeClassChildren(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", ncId);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
setDescription(String token, String uuid, String description) void Sets a description.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
okmRecord.setDescription(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", "some description");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createWizard(String token, String recPath, String title, long nodeClass) WizardNode Creates a new record with a wizard.
  • The parameter recPath should be any valid folder or record UUID

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.bean.WizardNode;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
WizardNode wn = okmRecord.createWizard(null, "1f323e88-64ee-4f57-91e2-9276f8c603f9", "PKI-100200", 0);
System.out.print(wn);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createMissingRecords(String token, String recPath) void Creates any missing records under the given path.
  • The parameter recPath should be a valid folder or record path in OpenKM.

Example:

package com.openkm;
import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
okmRecord.createMissingRecords(null, "/okm:root/PKI");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createFromTemplate(String token, String fldId, String dstPath, Map<String, String> properties, ExtendedAttributes extAttr) Record Creates a new record from a template folder and returns the created Record object.
  • The parameter fldId is the UUID of the template folder.
  • The parameter dstPath is the destination path where the record will be created.
  • The parameter properties is a map of property group values to set on the new record.
  • The parameter extAttr controls which extended attributes (categories, keywords, notes, etc.) are copied from the template.

Example:

package com.openkm;
import java.util.HashMap;
import java.util.Map;
import com.openkm.api.OKMRecord;
import com.openkm.bean.ExtendedAttributes;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
Map<String, String> properties = new HashMap<>();
properties.put("okp:group.property", "value");
ExtendedAttributes extAttr = new ExtendedAttributes();
extAttr.setKeywords(true);
extAttr.setCategories(true);
Record newRec = okmRecord.createFromTemplate(null, "b6848ac2-345f-454e-964a-eba4dcc020e6",
"/okm:root/PKI-100300", properties, extAttr);
System.out.println(newRec);
} catch (Exception e) {
e.printStackTrace();
}
}
}