🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Parsed/Derived settable attributes
This page was created by PageReplicator on 2025-09-01. Last edited by PageReplicator on 2025-09-01.

Template:Notice



What Are These?[<a href="/index.php?title=Documentation:Derived_settable_attributes&veaction=edit&section=1" class="mw-editsection-visualeditor" title="Edit section: What Are These?" data-bs-title="Documentation:Derived_settable_attributes">edit</a> | <a href="/index.php?title=Documentation:Derived_settable_attributes&action=edit&section=1" title="Edit section: What Are These?" data-bs-title="Documentation:Derived_settable_attributes">edit source</a>]

  • Derived attributes use an OCL expression to calculate the presentation of another attribute.
  • Derived settable attributes use EAL to do the reverse, i.e. setting the source attribute from the entered value. The user input is in the vInputParameter variable.

This opens up special handling of user input and "user shortcuts" in the UI - for example, accepting only a number as a time entry.

Example with Time (DateTime) and Decimal[<a href="/index.php?title=Documentation:Derived_settable_attributes&veaction=edit&section=2" class="mw-editsection-visualeditor" title="Edit section: Example with Time (DateTime) and Decimal" data-bs-title="Documentation:Derived_settable_attributes">edit</a> | <a href="/index.php?title=Documentation:Derived_settable_attributes&action=edit&section=2" title="Edit section: Example with Time (DateTime) and Decimal" data-bs-title="Documentation:Derived_settable_attributes">edit source</a>]

This example uses FromTimeText, HoursText, and ToTimeText for user input, but only FromTime and Hours for storing information in the database.

This special handling makes user input much simpler because it handles the user's need to change any of the three values, updating the others behind the scenes.

<a href="/File:TimeSpent_class_example.png" class="image" data-bs-title="File:TimeSpent_class_example.png" data-bs-filetimestamp="20171126122529"><img alt="TimeSpent class example.png" src="/images/d/de/TimeSpent_class_example.png" decoding="async" width="201" height="163" class="thumbimage" /></a>
<a href="/File:TimeSpent_class_example.png" class="internal" title="Enlarge"></a>
  • /Date is a derived attribute for easy access to a neighboring class containing the date in DateTime format.
  • /EffectiveToTime is a derived attribute used as a companion to the FromTime, again for symmetry in accessing the information.

Support function StringToTime()

To help the other function with conversion, a help function like this was created:

if aText.length <= 2 then
  DateTime.Parse('1900-01-01 ' + aText + ':00')
else
  DateTime.Parse('1900-01-01 ' + aText)
endif
  • Note the addition of ":00" to the text if it is short. This helps the user out of entering just the hour part.
  • '1900-01-01' is an ugly hack to prevent storing the current date as part of the time entry. It would still work, but this is slightly better.

Property Inspector[<a href="/index.php?title=Documentation:Derived_settable_attributes&veaction=edit&section=3" class="mw-editsection-visualeditor" title="Edit section: Property Inspector" data-bs-title="Documentation:Derived_settable_attributes">edit</a> | <a href="/index.php?title=Documentation:Derived_settable_attributes&action=edit&section=3" title="Edit section: Property Inspector" data-bs-title="Documentation:Derived_settable_attributes">edit source</a>]

Below is the property inspector setting for a derived settable attribute. Note the AttributeMode and then the OCL and OclSet code.

<a href="/File:DerivedSettable_property_inspector.png" class="image" data-bs-title="File:DerivedSettable_property_inspector.png" data-bs-filetimestamp="20171126123136"><img alt="DerivedSettable property inspector.png" src="/images/d/df/DerivedSettable_property_inspector.png" decoding="async" width="382" height="95" class="thumbimage" /></a>
<a href="/File:DerivedSettable_property_inspector.png" class="internal" title="Enlarge"></a>
/FromTimeText: String?[<a href="/index.php?title=Documentation:Derived_settable_attributes&veaction=edit&section=4" class="mw-editsection-visualeditor" title="Edit section: /FromTimeText: String?" data-bs-title="Documentation:Derived_settable_attributes">edit</a> | <a href="/index.php?title=Documentation:Derived_settable_attributes&action=edit&section=4" title="Edit section: /FromTimeText: String?" data-bs-title="Documentation:Derived_settable_attributes">edit source</a>]

OCL

if self.FromTime.notNull then
  self.FromTime.formatDateTime('HH:mm')
else
  String.nullValue
endif

EAL (OclSet)

self.FromTime := self.StringToTime(vInputParameter)
/HoursText: String?[<a href="/index.php?title=Documentation:Derived_settable_attributes&veaction=edit&section=5" class="mw-editsection-visualeditor" title="Edit section: /HoursText: String?" data-bs-title="Documentation:Derived_settable_attributes">edit</a> | <a href="/index.php?title=Documentation:Derived_settable_attributes&action=edit&section=5" title="Edit section: /HoursText: String?" data-bs-title="Documentation:Derived_settable_attributes">edit source</a>]

OCL

In Sweden, we use the comma instead of the dot as a decimal separator. Hard-coded replacement:

self.Hours.ToString('N2').Replace('.', ',')

EAL (OclSet)

Enable the use of both the comma and dot as decimal separators. Round to 2 decimals.

self.Hours := Decimal.Parse(vInputParameter.Replace(',', '.')).Round(2)
/ToTimeText: String?[<a href="/index.php?title=Documentation:Derived_settable_attributes&veaction=edit&section=6" class="mw-editsection-visualeditor" title="Edit section: /ToTimeText: String?" data-bs-title="Documentation:Derived_settable_attributes">edit</a> | <a href="/index.php?title=Documentation:Derived_settable_attributes&action=edit&section=6" title="Edit section: /ToTimeText: String?" data-bs-title="Documentation:Derived_settable_attributes">edit source</a>]

The to-time is all calculated and only exists when showing and entering values.

OCL

if self.FromTime.notNull then
  self.FromTime.AddHours(self.Hours.Value.ToDouble).formatDateTime('HH:mm')
else
  String.nullValue
endif
EAL (OclSet)[<a href="/index.php?title=Documentation:Derived_settable_attributes&veaction=edit&section=7" class="mw-editsection-visualeditor" title="Edit section: EAL (OclSet)" data-bs-title="Documentation:Derived_settable_attributes">edit</a> | <a href="/index.php?title=Documentation:Derived_settable_attributes&action=edit&section=7" title="Edit section: EAL (OclSet)" data-bs-title="Documentation:Derived_settable_attributes">edit source</a>]

Handle both setting Hours or FromTime based on what information is already present.

if self.FromTime.notNull then
  self.Hours := Decimal.Create(self.StringToTime(vInputParameter).Subtract(self.FromTime).TotalHours)
else
  self.FromTime := self.StringToTime(vInputParameter).AddHours(-self.Hours.ToDouble);
  0
endif
    

See also:

<a href="/Training:Derived_attributes_%26_associations" title="Training:Derived attributes & associations" data-bs-title="Training:Derived_attributes_&_associations">Derived attributes & associations</a>

<a href="/Documentation:Derived_settable_associations" title="Documentation:Derived settable associations" data-bs-title="Documentation:Derived_settable_associations">Derived settable associations</a>