CMDBuild - Tricks - autoValue
A old inventory listing written in german -- Denny Müller @ unsplash
CMDBuild is a CMDB by tecnoteca S.r.l. is powerful and nimble once you get to know it. In this post we’ll explore implementing AutoValue’s in a form to improve your data-entry workflow
CMDBuild as an CMDB-Solution
CMDBuild is a great tool to manage your IT Infrastructure and Asset Data with a lot of extensibility using through their API. It supports SOAP and REST interfaces, allowing you to use it as the brain of your organizations inventory management.
Its intuitive, class-based data modelling atop PostgreSQL allows you to let asset management grow as you grow.
Data Modelling based on Classes
Classes are used for modelling data. Define the characteristics of an asset with various field types provided by the database as well as custom types and lookups.
Relations defined by Domains make for the interconnected details of inventory and your business.
Cards and managing Information
Cards are instances of classes defining a specific asset.
Data Input and How to make it Faster
Adding new data is easy if you’re using the frontend via editable cards properties.
Adding items by hand can be cumbersome or error-prone, when it comes to calculations or lookups and options. Automatic Values enable calculation of card attribute fields based on data input in other fields.
Unfortunately this feature isn’t all that well documentated (a small error that I’m sure is going to be fixed in future iterations).
Automatic Values (or autoValue[s]
) can be defined in the attribute tab under the Administration Module.
In the attribute detail view allows you to modify individual attribute data characteristics and constraints.
How automatic values can be leveraged
Assuming a class BillingItem
with the following general details for attributes:
We could input each of these fields individually by hand or calculate at least NetAmount
representing the net amount of cost asked for a billing item.
AutoValues are defined as JavaScript inline evaluated scripts everytime you change a field during class input. Under the covers an AutoValue is a javascript function interacting with the current card or record you’re editing.
Looking at the source code we can find in the file ui/app/util/helper/FormHelper.js
:
/**
* Add auto value script to field
* @param {Object} config Ext.form.Field configuration
* @param {Object} fieldMeta Field metadata
* @param {Object} fieldMeta.validationRules Validation rules code
* @param {String} linkname
* @param {String} formmode One of `read`, `create` or `update`.
*/
addAutoValue: function (config, fieldMeta, linkname, formmode, activityLinkName) { ...
This is the method used when a new form is initialized and evaluates the javascript you defined in the
autoValue
field as a function with the parameter api
:
var jsfn = Ext.String.format(
'function executeAutoValue(api) 0',
script
);
The object api
passed into the function is defined like this:
var api = Ext.apply({
record: record,
activity: activity,
mode: formmode,
setValue: function (value) {
record.set(fieldMeta.name, value);
}
}, CMDBuildUI.util.api.Client.getApiForFieldAutoValue());
This means you can modify the currently opened record in the function by accessing the get
and set
functions on
the api.record
field to modify a given attributes or relations values.
For example adding the afforementioned NetAmount
based on amount
+ VAT
we can write it like so:
var VAT = api.record.get("VAT");
var amount = api.record.get("Amount");
if (VAT && amount) {
api.record.set("NetAmount", amount + amount * (VAT / 100));
}
Adding more for Amount based on rate and quantity to calculate the amount to come to the eventual net amount, we can now concentrate on the information we want to collect while the rest is calculated for us:
Closing Words
CMDBuild is powerful if you get the hang of it. I’ve grown to like it to manage assets even for my private environment simply because it allows me to manage all of my hardware and their warranties without having to rifle through piles of e-mails in my inbox or a drawer full of documents. Allowing information to be at your fingertips at a moments notice is so valuable in an ever evolving It infrastructure.
About CMDBuild
is a registered trademark, Tecnoteca srl