OpenWGA 7.6 - OpenWGA Concepts and Features

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

Using update processes

A special parameter that can be given to create and update operations is an "update process". It however is mainly intended to be used with HDBModel.updateContent() to perform a certain predefined modification procedure on content documents. This procedure may be a simple JavaScript function or a TMLScript module.

If there is a certain modification task that you frequently use on special content documents then you can predefine the code that is neccessary in some custom TMLScript module. For example, have a look at the following simple code that assigns a "task" document to the currently logged in user:

content().setItemValue("assignedto", meta("db", "username"));

content().setItemValue("status", "inprogress");

If we store this to a TMLScript module file named "assignToMe.tmlscript", we could use it as an update process with the updateContent() method. For this there is a method hdbModelParams.setUpdateModuleProcess() on the HDBModelParams object:

var params = HDBModel.newUpdateContentParams(content());

params.setUpdateModuleProcess(db(), "assignToMe");

HDBModel.updateContent(params);

Or, in a short version, using an argument variant of updateContent() without HDBModelParams:

HDBModel.updateContent(content(), "assignToMe");

This is some very short code which you could use to trigger complex processes.

However, why use this working scheme instead of just creating a WebTML action which modifies the content and then calls updateContent() in the end? While this would be a valid way to do it there are some advantages to the "update process" scheme:

  • The process code is only executed if the modification is allowed and not canceled by some event script. Depending on what you want to do it may be necessary to ensure, that the code does not run at all if the update process is canceled.
  • Some may regard this a "cleaner approach". You could keep your data modification code separate from the code that is directly triggered by the UI.