Sun Identity Manager Deployment Reference

Calculating Default Field Values

Field values can be calculated from other fields or simply set to an initial value using the <Default> element. The <Default> element is typically used to initialize an editable field and is evaluated only if the field does not already have a value assigned to it. The <Default> element is often used to calculate an account ID based on the first and last name of the user. The following example shows a field definition that uses string manipulation expressions to calculate a default account ID consisting of the first letter of the user’s first name concatenated with the user’s last name.

<Field name=’waveset.accountId’>
   <Display class=’Text’/>
      <Property name=’title’ value=’AccountID’/>
   </Display>
   <Default>
      <concat>
         <substr>
            <ref>accounts[AD].firstname</ref>
            <i>0</i>
            <i>1</i>
         </substr>
         <ref>accounts[AD].lastname</ref>
      </concat>
   </Default>
</Field>

The <Default> element is part of the Form XML language. This element can contain either an XPRESS expression or elements in another language called XML Object. (For more information on XML Object language, see the chapter titled Chapter 6, XML Object Language)

When this field is processed, the system checks to see if a value already exists for the waveset.accountId attribute. If no value exists, it evaluates the expression in the <Default> element. In this case, a value is calculated by concatenating the first letter of the first name with the last name.

You may need to make sure that firstname and lastname fields have values, as demonstrated by the following example:

   <cond>
     <and>
       <notnull><ref>accounts[AD].firstname</ref></notnull>
       <notnull><ref>accounts[AD].lastname</ref></notnull>
     </and>
     <concat>
       <substr>
            <ref>accounts[AD].firstname</ref>
            <i>0</i>
            <i>1</i>
        </substr>
       <ref>accounts[AD].lastname</ref>
     </concat>
   </cond>

The preceding code is structured as an if-then statement in other programming languages. This cond expression has two arguments:

First, the conditional expression is evaluated. If the result of this expression is logically true, the value of cond will be the value of the then expression. If the result of the conditional expression is false, the value of cond will be null.

In this example, the cond statement ensures that values exist for two account attributes before using them to calculate accountID. The Default expression will continue to be evaluated each time the form is refreshed or saved until the prerequisites are finally set or until the user provides a value in the field. The Default expression will not be evaluated if the associated field contains a non-null value.