Expression/Functions

From FlexRule Wiki
Jump to: navigation, search

Creating Objects

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

new JavaScript Platforms FlexRule Engine in .Net Platforms

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

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

For example, let's assume a type of 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 the building of nested values and structure simply by specifying the name of its properties using |key. Dynamic object automatically creates a 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 we also have registered 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 the IList<object> interface. You can then use the interface properties and methods (e.g., Add, Remove, etc.) to manipulate the list.

Format: array(exp1, exp2, exp3...)
Example: array (3.4, 145)
 Result: a list that has all of 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 add a null item to match the count (default -1, does not add null values)
Bulbgraph.png You can pass * for a 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)

notificationClear FlexRule Engine in .Net Platforms

Clears all of the notifications from all the groups based on the notice type.

notificationClear(type)
  • type (string): type of the message (i.e., error, warning or info)

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 split list (default true)
  • remove (bool): true to remove the empty items from a split list (default true)
  • minimumCount (number): if the split count result is less, will add a null item to match the count (default -1, does not add null values)

join FlexRule Engine in .Net Platforms

Concatenates the elements of 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 have more than one element (Mandatory)
  • members: list of members to concatenate (Mandatory)

concat FlexRule Engine in .Net Platforms

Concatenates the elements of 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 a left to right order

Math

min FlexRule Engine in .Net Platforms

Returns the smallest of two numbers.

min(value1, value2)

max FlexRule Engine in .Net Platforms

Returns the largest 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 the execution context

del(name)

Conditional

iff FlexRule Engine in .Net Platforms

To be used to determine whether 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 conditions must be used with iff.

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

|case is a monadic operator in 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 the local date and time now.

now()

nowUtc JavaScript Platforms FlexRule Engine in .Net Platforms

Returns local date and time 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 allow 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)

pathCreate FlexRule Engine in .Net Platforms

Creates a folder based on the path. If any internal folders do not exists, it creates them as well.

pathCreate(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.

pathCombine FlexRule Engine in .Net Platforms

Combines two strings into a path.

pathCombine(path1, path2, ...)
  • path1, path2,... (string): list of strings that are going to be concat as a single 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()

Processes

processRun FlexRule Engine in .Net Platforms

Executes a process and runs a command.

processRun(path, args)
  • path (required): command name or full path
  • args: a string that is the arguments of the command
  • return: A result object of {output, error}
    • output: success output of command
    • error: error output of the command
Example: list = processRun('cmd.exe', '/c dir').output
Result: Returns the result of dir command sets it in the list parameter

processList FlexRule Engine in .Net Platforms

Lists all the running processes.

processList()

processKill FlexRule Engine in .Net Platforms

Kills a running process

processKill(processId)

Object Wrapper

Proxy

A Proxy object allows accessing members (property and Methods) of objects with automatic translation between required types and native complex objects.

proxy(instance)
  • instance (required): The instance of an actual object
Bulbgraph.pngProxy is a smart object that knows how to translate between native complex values and static types.

soapClient

It creates a Proxy based on the WSDL address.

soapClient(name, wsdlUrl, serviceEndpointUrl) 
  • name (required): name of the service. This is used to cache the client (Proxy).
  • wsdlUrl (required): address of the service that provides WSDL information
  • serviceEndpointUrl: When service operation endpoint Url is different from the WSDL, it can be set using this parameter. Or the Url property of the client can be set separately.
  • returns: It returns a proxy instance to communicate to service. The proxy object has the attributes shown below:
    • Url [string]: endpoint address of the service to call
    • Timeout [int]: numbers of milliseconds for service call timeout (default 100,000)

Example:

p = soapClient('CheckQuantity', 'http://www.services.com/api?wsdl', 'http://www.services.com/api/v2')
products = p.GetProducts(['p1', 'p2'])