Calculating values of object properties

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

What do we mean by objects’ properties? It 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 the 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 we have 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) : " "
Caution
When writing a script for calculating field value, remember that a script is a function that always returns 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:

 

 

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