Specialized Administration > Tailoring Business Objects > Type and Attribute Management > Working with the Type and Attribute Management Utility > Managing Types > Type Information Page > Attributes Tab > Creating a New Attribute > Calculated Attribute Formulas
  
Calculated Attribute Formulas
Calculated attributes use formulas to derive their values from the values of other attributes. These formulas can use both attribute and literal values to compute or generate a derived attribute value.
You can enter the formula in the Formula field during the Set Properties step of creating the calculated attribute, or by editing the Formula field on the attribute information page once the calculated attribute has been created.
* 
If an attribute affecting a calculated attribute is modified when creating or editing an object, the formula is not immediately reevaluated. Once the create action or edit action is processed, the formula is reevaluated and the calculated attribute value is updated.
For information on how calculated attributes are displayed when included in attribute layouts, see Attribute Display.
Localization of the numeric results of a calculated attribute is based on the browser locale.
Data Types in Formulas
Only attributes of the following data types are supported in formulas: String, Integer Number, Real Number, Real Number with Units, Hyperlink, Date and Time, and Boolean. The result of the formula must match the specified data type of the calculated attribute, but attributes of different data types can be used within the formula itself.
When attributes of different data types are used within the formula, the system converts the data types to the same data type as required for the operation or function used in the formula, before performing the operation or function. The formula result is in that same data type. The data type conversion is applied in the following priority order:
1. String—if at least one argument in the formula has a data type of String, all arguments are converted to have a data type of String. (Hyperlink and Date and Time are automatically converted to String.)
2. Real Number with Units—if at least one argument in the formula has a data type of Real Number with Units, all arguments are converted to have a data type of Real Number with Units.
3. Real Number—if at least one argument in the formula has a data type of Real Number, all arguments are converted to have a data type of Real Number.
4. Integer Number—if at least one argument in the formula has a data type of Integer Number, all arguments are converted to have a data type of Integer Number.
5. Boolean.
For example, in the formula attrA + attrB, if attrA is a String data type and attrB is a Real Number data type, attrB is converted to a String data type and concatenated with attrA. If the value of attrA is Result: and the value of attrB is 1.5, then the result of the formula is Result:1.5.
Similarly, if attrC is an Integer Number data type, and attrD is a Real Number data type, then in the formula attrC * attrD, attrC is converted to a Real Number data type, and the result of the formula is a Real Number data type.
The system evaluates the formula entered when the calculated attribute is saved. If the data type of the formula result does not match the data type of the calculated attribute, an error is returned and the formula is not saved. The data type of a formula result can be converted by changing how the formula is specified. In the following, <formula> is the original formula whose data type is being converted.
To convert a formula resulting in a Boolean, Integer Number, Real Number, or Real Number with Units to a String data type, enter the following in the Formula field:
""+(<formula>)
To convert a formula resulting in a Boolean, Integer Number, or Real Number data type to a Real Number with Units data type, enter the following in the Formula field:
unit("1.0000000000000")*(<formula>)
(At least thirteen zeroes are required to preserve the full precision of the original result.)
To convert a formula resulting in a Boolean or Integer Number data type to a Real Number data type, enter the following in the Formula field:
1.0*(<formula>)
To convert a formula resulting in a Boolean data type to an Integer Number data type, enter the following in the Formula field:
1*(<formula>)
Example: Calculating a Numerical Value
Use operators and internal names of attributes to build formulas which calculate the desired attribute value. (You must use the Internal Name of an attribute in formulas, rather than its Display Name.)
For example, if you had a Total Cost attribute, which is meant to be the value of the Quantity attribute multiplied by the value of the Unit Cost attribute, plus the value of the Handling Fee attribute, you could use the following formula to calculate the Total Cost attribute value:
(quantity*unitCost)+fee
Example: Combining Non-Numerical Attribute Values
Formulas can also be used to combine non-numerical attribute values.
For example, if you created a calculated attribute named ID, you could combine the values of the Name and Number attributes of the type as the value of the ID attribute using the following formula:
name+"("+number+")"
This would result in an ID attribute value such as MyDocument(0001A).
Supported Functions
* 
There are no multi-valued functions currently supported for calculated attributes.
The following functions are supported:
Function
Description
isNull( )
Null check
unit( )
Convert String data type to Real Number with Units data type
str( )
Convert number to String data type
abs( )
Absolute value or magnitude
avg( )
Average of a list of values
sum( )
Sum of a list of values
min( )
Minimum of a list of values
max( )
Maximum of a list of values
round()
Converts a number with a decimal (real number) into an integer number
When the decimal contains .5, the number is rounded to an even number (for example, 30.5 is rounded down to 30 and 31.5 is rounded up to 32)
When the decimal contains other numbers, the number is rounded to the nearest number (for example, 30.8 is rounded up to 31 and 33.4 is rounded down to 33)
mod()
Returns the remainder of one number divided by another number. (Integer data types, only)
${}
Wraps attribute internal names which include special characters, so they can be used within the formula. All attribute internal names can be wrapped, but attribute internal names which include the dash (-), dollar sign ($), or square brackets ([ ]) must be wrapped when used in formulas. For example, attributes with internal names of my-attribute or my[very$complex]-attribute can be used in a formula when wrapped as follows:
${my-attribute}
${my[very$complex]-attribute}
If the attributes used in the Example: Calculating a Numerical Value section had internal names which include special characters, the formula for the Total Cost attribute could appear as follows:(${item-quantity}*${unit-cost})+${handling-fee}
Supported Operators
The following operators are supported:
Operator
Description
+
Addition; can also be used to concatenate strings
-
Subtraction
*
Multiplication
/
Division
( )
Open and closed parentheses, to indicate a different priority in the order of operations (the operations within the parenthesis are to be performed first)
" "
Double quotes, to indicate that the content of the quotes is a literal string. Any non-number not inside double quotes is treated as an attribute name
>
Greater than
<
Less than
>=
Greater than or equal to
<=
Less than or equal to
==
Equal to
!=
Not equal
^
Power or exponentiation
&
And
|
Or
~
Not
^*
Exclusive or
&&
And
||
Or
!
Not
? :
Conditional operator, indicating the result if the specified condition is true or false:
(condition) ? value if true : value if false
For example, assume that a type has attributes of length, width, and shape, where shape is a calculated attribute with the following formula:
(length>width) ? "longer" : "wider"
If the value of the length attribute is greater than the value of the width attribute, then the shape attribute is assigned a value of longer. If the value of the length attribute is not greater than the value of the width attribute, then the shape attribute is assigned a value of wider.
%
Remainder