Curriculum: define conditions and calculated fields
- In this lesson:
- 1Calculated fields using expressions
- 2Expression structure: <field/value><operator><field/value>
- 3Expression structure: <function()>
- 4Conditional rules
- 5Rule configuration: <field> in (<value>, <value>)
- 6Rule configuration: <field><operator><field or value>
- 7Rule configuration: <logical operator>
- 8Testing configured conditions and calculated fields
- 9
- 10
- 11
Calculated fields using expressions
Curriculum supports usage of expressions in different functional areas of the system. For instance:
- the code or other identifying fields are calculated based on an expression based on other fields and specific functions to guarantee unique code creation
- the value of custom-fields, where an expression is defined using other fields. For instance 'contact hours' is automatically calculated based on the number of credits * <norm hours per credit>
- the calculation of hours in workload planning, where the hours for a lecturer is a calculation of number of students, duration of the activity, number of activities, etc.
The configuration of an expression can be done by the admin.
The logical / mathematical expressions supported are:
- <field/value><operator><field/value>
- <function()>
Expression structure: <field/value><operator><field/value>
Calculate the value of a new field based on another field and/or a fixed value.
The supported operators are:
- + (add)
- - (substract)
- * (multiply)
- / (divide)
- % (remainder)
The field is identified by the Code. In case a <field> occurs in multiple objects, f.i. credits/optimum and capacity/optimum, the convention to specify the correct <field> is <colon>(<object>) <field>, f.i. :(credits) optimum.
Examples are:
- (:contactHours * 3) + 100
- :(credits)optimum) / 2
- :contactHours * :(capacity)optimum
- :contactHours + :selfStudyHours
Expression structure: <function()>
Calculate the value of a new field using a function that is based on other fields and values.
The supported functions are:
- join (value, value, ...) - Concatenate fields / values
- coalesce (value, value, ...) - The first non-empty value will be taken, e.g. if <value A> = "" then <value B>
- take (value, length, filler) - Take the left X characters. If there are less than X characters af filling character can be specified to end-up with X characters
- floor (value) - Take the integer value of a number value, e.g. 2.5 -> 2
- round (value) - Round the integer value of a number, e.g. 2.5 -> 3
- min (value) - Take the lowest value of the specified values
- max (value) - Take the highest value of the specified values
- generate (length, filler, first_value, increment) - Generate a unique number to guarantee uniqueness based on the other part of the calculated field
join(:typeId,'-',:abbreviation,'-',take(floor(:(credits) optimum), 3, '0'),'-',generate(3, '0', 10, 1))
In case fields are used, they are identified by the Code. In case a <field> occurs in multiple objects, f.i. credits/optimum and capacity/optimum, the convention to specify the correct <field> is <colon>(<object>) <field>, f.i. :(credits) optimum.
Examples are:
- join("City = ", :location) that results in "City = AMS"
- floor(:(credits) optimum)
- take(floor(:(credits) optimum), 3, '0'), result in 003 if credits is 3 or in 012 if credits is 12.5 (floor 12.5 = 12).
- round(:contactHours)
- round((:contactHours / 3) + (:students * 0.3))
- coalesce(:maxStudents, :students, 100), will pick the first 'not empty' value in the defined order. So if maxStudents is empty students is taken.
- min(:capacity, 50)), will take the lowest of the two values. If :capacity > 50 then 50 else :capacity
- max(:capacity-50, 0)), will take the highest of the two values. If :capacity-50<0 then 0 else :capacity
- generate(3, '0', 10, 1)), will create a unique extension010, 011, 012, ...., 999
Conditional rules
The configuration supports definition of conditional rules. These rules can be used to prevent fields from showing, skip workflow steps or process statuses.
On a field definition it will be possible for the administrator to configure the visibility of the field:
- It will be added to the field configuration, which means that the 'visibility' is global and not specific for a screen
- It is presumed the system administrator is knowledgable to define the definition and doesn't need complex configuration options to do so.
- Fields supported are 'additional fields' and 'descriptions'.
The field configuration should allow the system administrator to define the rule to 'show' the field, based on a field (on the object, and/or on the same page).
The rendering for these cases will be different. In case the object is on the page, it might be that the fields will appear on the screen after selection of a specific value. On toggle in screen, the existing data will be deleted, in case a field is made invisible.
The configuration of a conditional rule can be done by the admin.
The rules supported are:
- <field> in (<value>, <value>) - is the value of the field in the list of values, e.g. typeId in ('BA', 'MA', 'PHD')
- !<field> in (<value>, <value>) - is the value of the field NOT in the list of values !typeId in ('BA', 'MA', 'PHD')
- <field><operator><field or value> - operator values || (or) and && (and), e.g. :typeId in ('PHD','MA') && :(credits)optimum < 120
- <logical operator> - operator values >, >= , <, <=, =, !=
Rule configuration: <field> in (<value>, <value>)
Conditional execute / show information based on the value of another field and/or a fixed value.
The field is identified by the Code. In case a <field> occurs in multiple objects, f.i. credits/optimum and capacity/optimum, the convention to specify the correct <field> is <colon>(<object>) <field>, f.i. :(credits) optimum.
Examples are:
- :(module)typeId in (STANDARD, MOOC)
- :free_choice in (true)
- :country in ('EN', 'NL', 'DE', 'SW')
- :country not in ('UK', 'ES')
Rule configuration: <field><operator><field or value>
Only show the field in case the expression with referenced field or value is met.
The supported functions are:
- >
- >=
- <
- <=
- !=
In case fields are used, they are identified by the Code. In case a <field> occurs in multiple objects, f.i. credits/optimum and capacity/optimum, the convention to specify the correct <field> is <colon>(<object>) <field>, f.i. :(credits) optimum.
Examples are:
- :nr_of_students < 100
- :max_credits < 6
- :nr_of_students < :max_students
- :(credits) optimum <= :(credits) max
Rule configuration: <logical operator>
Only show the field in case the expression is met.
The supported functions are:
- && or AND
- || or OR
In case fields are used, they are identified by the Code. In case a <field> occurs in multiple objects, f.i. credits/optimum and capacity/optimum, the convention to specify the correct <field> is <colon>(<object>) <field>, f.i. :(credits) optimum.
Examples are:
- :type = 'Minor' and :location = 'AMS'
It is advised to enclose the operands with single quote to allow values like 'AMS-A' - :type = 'Minor' && :location = 'AMS'
- :location in ('AMS','RTD') or :country='UK'
- :location in ('AMS','RTD') || :country='UK'
Testing configured conditions and calculated fields
Configured expressions for a calculated fields and conditions can be tested via the test tool.
Click on the v-mark to open the test tool for the configuration rule or expression.
Select an educational object (just start typing the name of a study, module group or module) and click on Evaluate to check the result.