Expression/Functions

From FlexRule Wiki
Jump to: navigation, search

Creating Objects

Expression allows new objects been created from a registered type. Please note to register a type in modeling level using can be used.

new JavaScript Platforms FlexRule Engine in .Net Platforms

This is a global function allowing the creation of new instance from a registered and defined non-generic type. The type must be registered in the context and must have a default constructor. Please note if the Type is generic, newOf must be used.

Format: new(Type)  FlexRule Engine in .Net Platforms

For example let's assume type Book is registered.

Example: b = new (Book)
 Result: assigns a new instance of Book to parameter named b

When Type is not provided, then a FlexRule dynamic object is created.

Format: new()  JavaScript Platforms FlexRule Engine in .Net Platforms

The dynamic object allows building nested values and structure with just specifying the name of properties using |key. Dynamic object creates automatically nested structure as new nested properties are assigned.

newOf FlexRule Engine in .Net Platforms

This is similar to new but it creates an object from a generic type.

Format: newOf(Type, ArgType1, ArgType2...)

For example let's assume type Book is registered and also, we have register a System.Collections.Generic.List<> as a GenericList name.

Example: newOf (GenericList, Book)
 Result: creates a new instance of List<Book>. A generic list that can hold Book objects.
array JavaScript Platforms FlexRule Engine in .Net Platforms

Builds a sequence of values that implements IList<object> interface. You can then use the interface properties and methods e.g.Add, Remove to manipulate the list.

Format: array(exp1, exp2, exp3...)
Example: array (3.4, 145)
 Result: a list that has all the provided values.

Example: array ()
 Result: an empty list.

Notification

notification FlexRule Engine in .Net Platforms

Retrieves the notification in a default or specific group that has some notices

notification(type, group)
  • type (string): the type of message i.e. error, warning or error (optional)
  • group (string): group name of notification. When not specified, the default group is chosen. (optional)
  • return (Notice): if the split count result is less, will and a null item to match the count (default -1, does not add null values)
Bulbgraph.png You can pass * for type or group that queries all the types or groups

notificationWrite FlexRule Engine in .Net Platforms

Writes a message with a specific type in a notification

notificationWrite(type, message, group)
  • type (string): type of the message. i.e. error, warning or info
  • message (string): the message to be written in a notification. It can be parameterised string. (Mandatory)
  • group: name of group in the notification (Mandatory)

String

split FlexRule Engine in .Net Platforms

Splits a string into substrings that are based on the characters in an array.

split(value, splitter, trim, remove, minimumCount)
  • value (string): a value to be split (Mandatory)
  • splitter (string, array): splitter char, string or an array of multiple splitter (Mandatory)
  • trim (bool): true to trim each item in the slit list (default true)
  • remove (bool): true to remove the empty items from split list (default true)
  • minimumCount (number): if the split count result is less, will and a null item to match the count (default -1, does not add null values)

join FlexRule Engine in .Net Platforms

Concatenates the elements of a specified members of a collection/array, using the specified separator between each member.

join(separator, members)
  • separator: The string to use as a separator. separator is included in the returned string only if values has more than one element. (Mandatory)
  • members: list of members to concatenate. (Mandatory)

concat FlexRule Engine in .Net Platforms

Concatenates the elements of a specified members of a collection/array without any separator between each member.

concat(members)
  • members: list of members to concatenate. (Mandatory)

trim FlexRule Engine in .Net Platforms

Removes all leading and trailing white-space characters (or specified ones) from the current string.

trim(stringValue, characters)
  • stringValue: the string value to trim (Mandatory)
  • characters: list of characters to be used for trim in the left to right orders

Math

min FlexRule Engine in .Net Platforms

Returns the smaller of two numbers.

min(value1, value2)

max FlexRule Engine in .Net Platforms

Returns the larger of two numbers.

max(value1, value2)

floor FlexRule Engine in .Net Platforms

Returns the largest integer less than or equal to the specified number.

 floor(value)

round JavaScript Platforms FlexRule Engine in .Net Platforms

Rounds a numeric value to the nearest integral value.

round(value, decimals)

log FlexRule Engine in .Net Platforms

Returns the natural (or other base for) logarithm of a specified number.

log(value, base)

value: the number to calculate log (Mandatory) base: base for the log (default is e)

abs FlexRule Engine in .Net Platforms

Returns the absolute value of a double-precision floating-point number.

abs(value)

Variable

def FlexRule Engine in .Net Platforms

Defines a variable in the execution context

def(name, value)
  • name (string): name of variable
  • value: value (default is null)

del FlexRule Engine in .Net Platforms

Deletes a variable from execution context

del(name)

Conditional

iff FlexRule Engine in .Net Platforms

To be used to determine if another expression is true or false. If the expression is true, it returns one value; if it is false, it returns another.

iff(expression, then, else)

case FlexRule Engine in .Net Platforms

Evaluates a list of conditions and returns one of multiple possible result expressions. to provide multiple condition must be used with iff.

null |case(conditions, else)
  • conditions: list of conditions to be evaluated
  • else: if no conditions meet, it returns this value

|case is a monadic operator which the input of the monad has no effect on the result

Example:

null|case(iff(a==1, 'ok1'), 
          iff(a==2, 'ok2'),
          'nok')

DateTime

today FlexRule Engine in .Net Platforms

Returns the local date for today.

today()

todayUtc JavaScript Platforms FlexRule Engine in .Net Platforms

Returns today's date in Coordinated Universal Time (UTC).

todayUtc()

now FlexRule Engine in .Net Platforms

Returns local date and time for now.

now()

nowUtc JavaScript Platforms FlexRule Engine in .Net Platforms

Returns local's date and time for now based on Coordinated Universal Time (UTC).

nowUtc()

date FlexRule Engine in .Net Platforms

Builds a local date and time with different components.

date(year, month, day, hour, minute, second, millisecond)

dateUtc JavaScript Platforms FlexRule Engine in .Net Platforms

Builds a date and time with different components based on Coordinated Universal Time (UTC).

date(year, month, day, hour, minute, second, millisecond)

dateDiff JavaScript Platforms FlexRule Engine in .Net Platforms

Returns the time between two dates based on an interval.

dateDiff(interval, date1, date2)
  • interval (string): years, months, weeks, days, hours, minutes, seconds, milliseconds, offset
  • date1 (datetime): beginning date
  • date2 (datetime): end date

dateDiff would calculate date1-date2 expression agnostically. When offset is selected for the interval, the result is an array of values for [days, hours, minutes, seconds, milliseconds] otherwise the value is a number.

Example 1:

dateDiff('years', date1, date2)

dateAdd JavaScript Platforms FlexRule Engine in .Net Platforms

Adds a slot of time to a date based on an interval.

dateAdd(interval, date1, value)
  • interval (string): years, months, days, hours, minutes, seconds, milliseconds
  • date1 (datetime): beginning date
  • value (number): the value to be added to the date

Returns the new date/time.

Example 1:

dateAdd('months', date1, 23)

IO

IO operations allows you to read/write files from local and network files. Or create folders and access current directories.

fileWrite FlexRule Engine in .Net Platforms

Creates a new file, writes the specified content to the file, and then closes the file. If the target file already exists, it is overwritten.

fileWrite(path, content)

fileAppend FlexRule Engine in .Net Platforms

Opens a file, appends the specified content to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file.

fileAppend(path, content)

fileReadText FlexRule Engine in .Net Platforms

Opens a text file, reads all lines of the file, and then closes the file.

fileReadText(path)

fileReadBytes FlexRule Engine in .Net Platforms

Opens a binary file, reads the contents of the file into a byte array, and then closes the file.

fileReadBytes(path)

fileExists FlexRule Engine in .Net Platforms

Determines whether the specified file exists.

fileExists(path)

fileDelete FlexRule Engine in .Net Platforms

Deletes a file.

fileDelete(path)

pathExists FlexRule Engine in .Net Platforms

Determines whether the given path refers to an existing directory on disk.

pathExists(path)

fileTemp FlexRule Engine in .Net Platforms

Creates a zero size file at a temp directory and returns the full path.

fileTemp()

pathCurrent FlexRule Engine in .Net Platforms

Gets or sets the fully qualified path of the current working directory.

pathCurrent(path)
  • path (string): when it is set, will update the current path.

pathTemp FlexRule Engine in .Net Platforms

Gets a new temp directory fully qualified path which ends with \ character. The returned folder exists and is empty.

pathTemp()