OpenWGA 7.10 - OpenWGA Concepts and Features

Design and development » HDBModel framework » HDBModel in TMLScript » The "HDBModel" object

Assigning content ids

The HDBModel object method HDBModel.assignContentID() can be used to assign a content document a custom content id.

The content id, already introduced in Navigating and querying the HDBModel hierarchy is an id which uniquely identifies a content at the current hierarchy position. It is used to build the unique name of a content document for easier navigation.

The content id is automatically generated by default as a random hexadecimal string. But if you have anything on your content document which already is a unique identifier you may want to use it as content id.

Imagine a user management app having the following model:


  <storage sid="users">

    <content contentclass="user">

      <item name="username"/>




The content class "user" has a predefined item "username" which should hold the name of a defined user. As this should be unique among users and may be used to fetch any user it is a good candidate for usage as content id.

The method "assignContentID()" is best used inside the event script "onSave" for this content clas which is called any time a user document is created or updated:

this.onSave = function(e) {

  HDBModel.assignContentID(content(), username);


Here we call the "assignContentID()" method giving it the current WGAPI content document as parameter plus the item "username".

As a result of this the OpenWGA Content Store will automatically check those usernames for uniqueness. Another result is that we can use the user name to navigate to individual users in a  convenient way via context changes:

<tml:range context="name:users/np:username">



Here we first change context to the storage "users" by using its storage id, then continue using any user name as "name part" that extends the unique name of the current document. This is actually equivalent to doing:

<tml:range context="name:users.username">



But the "np" syntax should be preferred as it automatically converts the input names regarding namepart rules.