Calculating values of object properties

In ELMA you can automatically calculate values of object properties using C# scripts.

Object properties can be a context variable of a business process, properties of ELMA objects and attributes of document types/project types.

To create a script for calculating a property value, in ELMA Designer go to the settings of an object property and open the Advanced tab:

In Value calculation type field choose C# script:

type script

For example, in ELMA, there is a Contact object. It has Last Name, First Name, Middle Name properties:

contact object

Let’s add a new Full Name property and create a script to calculate the value of this property automatically:

full name property

The script code will be the following:

(!string.IsNullOrEmpty(Firstname) && !string.IsNullOrEmpty(Middlename) && !string.IsNullOrEmpty(Surname)) ? string.Format("{0}. {1}. {2}", Firstname.Substring(0,1), Middlename.Substring(0,1), Surname) : " "
When writing a script for calculating a field value, remember that a script is a function that always returns a value.
Before performing any actions with the data, be sure to add the validation of an empty value (null), otherwise, an error will occur when starting the server.

In this script, you can only use the property values of the given object. You can also call the object methods. 

For example, the User object has a method that returns the full name. To call the method, use the following code: 
this.GetFullName()// A method that returns the full name

Now we need to publish the object and restart the ELMA server. Once the new Contact is created in the web application, ELMA will automatically calculate the value of the Initials property:


The above is applicable only to extensible system entities, excluding custom objects created by a user in the ELMA Designer.