Step 4 Code Fragment Virtual Fields

Visual LANSA

Step 4. Code Fragment Virtual Fields

REP008 - Virtual Fields

In this step you will use a Code Fragment derivation to:

  • Assign the length of the Notes field to the iiiNoteLength virtual field and
  • To set the value of the iiiEmployYears fields to be the number of years the employee has been with the company.

1.  Select the iiiNoteLength field in the list of Undefined virtuals.

2.  In the Details tab, enter the following:

Virtual field type

Code Fragment

Derive value when record is read

Select for Yes

Virtual Field Derivation

#iiiNoteLength := #iiiEmployNotes.CurChars

Replace iii with your initials.

     Your Details tab should now look like this:

     The code fragment uses an RDMLX intrinsic method CurChars to determine the number of characters in the iiiEmployNotes field and assigns the result to the iiiNoteLength field.

3.  The iiiNoteLength field will now be listed under the Read virtuals.

     Next you will set the iiiEmployYears field to show how many years an employee has worked for the company based on the Start Date field.

4.  Select the iiiEmployYears field in the list of Undefined virtuals.

5.  In the Details tab, enter the following:

Virtual field type

Code Fragment

Derive value when record is read

ü Select this option

Virtual Field Derivation

#iiiEmployYears := #iiiStartDate.Date.Now.Difference(#iiiStartDate) / 365

(you can copy and paste this code from the online guide Tutorials, substituting your initials for iii)

 

     Your Details tab should now look like this:

     The code fragment uses RDMLX intrinsic methods Date and Difference to compare the date portion of the iiiStartDate field with today's date and divides the result by 365.

     All your virtual fields are now listed under Read Virtuals.

6.  Compile the file and ensure the compilation ends without errors.