Adding attributes together

This example demonstrates how to add two numeric attributes together and store the result in a third numeric attribute.

To add two numeric attributes together:
  1. In Object Designer, create two numeric attributes (for example, Int16) on the Incident Management\Incident object called X and Y.
  2. Set the Default Value for X and Y to 0.
    This ensures that the calculation works immediately. If you do not set a default value, the values of X and Y will initially by NULL, which cannot be resolved by the calculation.
  3. Create a numeric attribute called XplusY.
  4. In the Properties grid for XplusY, set Calculation Type to BeforeSave.
    The Edit Formula for XplusY appears. The Editor box already contains:
Copy
import System
static def GetAttributeValue(Incident):
    Value =
    return Value
  1. Click at the end of the line Value = , then in the Attributes tree, double-click X.
    Incident._X is added to the end of the Value line. Incident is the name of the business object, and _X is the name of the attribute that you created called X. (The _ before the attribute name shows that it is a user-added attribute.)
  2. In the Operators tree, double-click Plus ( + ).
    + is added to the calculation.
  3. In the Attributes tree, double-click Y.
    Incident._Y is added to the end of the Value line.
    The final calculation in the Editor is:
Copy
import System
static def GetAttributeValue(Incident):
    Value = Incident._X + Incident._Y
    return Value

Note the single indentation of the final two lines - make sure you keep this indentation.

  1. Click Test Syntax to confirm that the calculation contains no errors in its structure, then click OK.
    The Calculation is added to the attribute.
  2. Save the changes to the object, then start Window Manager.
  3. Open the Incident window, and add the attributes X, Y and XplusY.
  4. In the Properties grid for both X and Y, set Is calculate on change to True.
    This will make XplusY update whenever X or Y are changed; if you do not set this property to true, XplusY will update only when you save the incident.