Skip to content

DataSplice Support Website

Sections
Personal tools
You are here: Home » Product Manuals DataSplice 3.0 » DataSplice Administration Client Manual » Attribute Expression Language

Attribute Expression Language

At times, it is useful to define an attribute value when it is used, not when it is defined. Dynamic attributes provide this ability. They get their values by evaluating an expression, which in turn can reference other attributes, access data in other views, or test complex conditions.

Dynamic attributes are processed by both the DataSplice Server and the Remote Client, so they work online as well as offline.

These attributes can be used for a wide range of tasks:

  • Look up values, such as default codes, associated with the current log in to reference in filters and defaults.
  • Fill out basic information for newly inserted records, like locations and descriptions.
  • Use existing restrictions from the master application as mandatory filter criteria.

Dynamic attributes are specified with the prefix :=. This tells the attribute processor to parse the attribute and return the evaluated value of the expression.

Expressions can be written as generic logical statements, similar to SQL where clauses. Normal operator precedence rules are followed. Parentheses can be used to arbitrarily group items. The following operators are understood:

  • + Numeric addition
  • - Numeric subtraction
  • * Numeric multiplication
  • / Numeric division
  • || String concatenation
  • <=> Comparison - returns -1 if the left argument is less than the right one, 1 if it is greater, and 0 if they are equal.
  • ! Boolean not operator (i.e.: !isModified())
  • is null
  • is not null
  • = or == Equality test - if the right argument is a pattern (/<regular expression>/) this will return if the left argument matches the given expression.
  • != or <> Inequality test - supports patterns the same way as equality tests.
  • > Greater than
  • < Less than
  • >= Greater than or equal
  • <= Less than or equal
  • like This processes % characters as wildcards
  • not like
  • between Inclusive bounds test (i.e.: ${value} between <min> and <max>)
  • not between
  • and
  • or

Note: Text operators are case-insensitive.

Attribute Functions

In addition to basic operators the attribute language also supports functions to perform additional attribute processing. Like the text-operators above, function names are case-insensitive.

In addition to being used for attribute processing, these functions can also be evaluated in any of the condition statements.

Min ( <value1> [, ... ] )
Returns the smallest of a list of values. At least one argument must be supplied. For instance:

:= min(5, ${SomeValue}, ${AnotherValue} + 1)

Max ( <value1> [, ... ] )
This is the same as min, but it returns the largest value in the list.
Floor ( <value> )
Returns the largest integer less than the specified value.
Ceiling ( <value> )
Calculates the ceiling of the specified value.
Test ( <condition>, <true value>, <false value> )
Evaluates an expression and returns different values depending on the result. This function takes three arguments: an expression to evaluate, the value to return if the expression is true, and the value to return if it is false.

All of these arguments can themselves be expressions if desired. For instance:

:= test(${Status} == "Complete", upper(${Something}), ${First} || ${Last})

Decode ( <expression>, <test 1>, <value 1> [, <test 2>, <value 2> ]... [, <default> ] )
Compares the expression against several values to return a particular value. This will compare the specified expression to each test n statement in order and return the corresponding value term if the expressions match. Because the internal equality operator is used for the comparison the test case can be patterns to perform regular expression matches.

If an unmatched parameter occurs at the end it will be returned if no matching value was found. Otherwise this function returns null if nothing matches.

:= Decode(${Status}, 10, "Critical", /^[56789]$/, "High", "Normal")

Eval ( <expression 1>, <value 1>, [, <expression 2>, <value 2> ]... )
Evaluates expressions in turn and returns the associated value for the first one that evaluates to true. This is similar to the Test function, except it supports any number of cases.

For instance, the example for Test above could be written as:

:= eval(${Status} == "Complete", upper(${Something}), true, ${First} || ${Last})

Lower ( <text> )
This returns a value in lowercase. The single argument specifies the text to modify.
Upper ( <text> )
This is the same as lower, but returns things in uppercase.
Length ( <text> )
Returns the number of characters in the specified argument.
Match ( <text>, <expression> )
This returns whether or not a value matches a particular regular expression. This takes two arguments: the text to search and the pattern to match against. For instance:

:= match(${Email}, /\w+@\w+\.(com|net|org)/)

Note that the equality operator supports this same functionality. The above example could also be written:

:= ${Email} = /\w+@\w+\.(com|net|org)/

Find ( <text>, <expression>, [group] )
This is similar to match, but returns a matching subgroup from the pattern. This can take up to three arguments: the text to search, the pattern to use, and the index of the group to return. The last argument is optional.

Group indexes work as you would expect them to. 1 specifies the first set of parentheses, 2 the second, and so on. 0 refers to the entire match. If no group argument is specified, this function returns the first match group or the entire match if there are no parentheses in the pattern.

:= find(${Address}, /(\w+):\/\//)

This will return http if Address is http://www.datasplice.com/. The function returns null if the text does not match the pattern.

Substitute ( <text>, <expression>, <replacement> )
This performs text substitution using regular expressions. This function takes three arguments: the text to process, the pattern to use, and the replacement text. The replacement text can refer to backreferences in the pattern using \1, \2, etc.

For instance, to change from <Last Name>, <First Name> to <First Name> <Last Name> we could use:

:= substitute(${FullName}, /(\w+),\s*(\w+)/, /\2 \1/)

IsInsert ()
This takes zero arguments and returns whether or not the current record is a new record.
IsUpdate ()
This works similarly to IsInsert, but returns whether or not the current record is modified.
IsDelete ()
Again similary to IsInsert, but returns if the current record has been marked for deletion.
IsModified ( <field name> )
This returns whether or not a particular field in the current record is modified. The single argument should be the name of the field in question.

:= test(IsModified("Status"), "modified", "not modified")

IsConnected ()
Returns whether or not a connection is currently established with the server. If evaluated on the server this will always return true.
IsAdmin ()
Returns whether or not the user associated with the current connection is a member of the Administrators group.
Query ( <view name>, <field name>, <where clause>, [order by clause] )
This performs a query against a target view and returns a value from the first matching record. Up to four arguments can be specified: the name of the view to query, the name of the field that contains the desired value, the where clause (without the keyword where), and an order by statement to sort the returned records. The Order By argument is optional.

Example:

:= query("Child View", "ID", "User = ${DS_USER} and Status <> 4")

HasError ()
This can be used during event processing to determine if an error has occurred. Otherwise this will return false.
HasConflict ()
This can be used during event processing to determine if an conflict has been detected. Otherwise this will return false.
Now ()
Returns the current date and time.
CreateDate ( <year>, [month], [day], [hour], [minute], [second] )
Constructs a date and time value given the specified values. If values are not specified, values from January 1, 12:00 AM are used.
AlterDate ( <date>, <days>, [hours], [minutes], [seconds] )
Adds the specified amount of time to a particular date. The specified values can be negative to obtain a value prior to the date.
TruncateDate ( <date>, < "year" | "month" | "day" | "hour" | "minute" > )
Truncates a date to the specified precision. For example:

:= TruncateDate("2005-12-03 12:34:56 PM", "month")

returns 2005-12-01 12:00:00 AM.

CompareDates ( <lhs>, <rhs>, < "year" | "month" | "day" | "hour" | "minute" > )
Compares dates truncated to the specified precision. This is useful to determine if the values are on the same day even if the times are different.

This returns -1 if lhs is before rhs, 1 if it is after, and 0 if the truncated dates are the same.

GetYear ( <date> )
Returns the year portion of the specified date as a number.
GetMonth ( <date> )
Returns the month portion of the specified date as a number.
GetDay ( <date> )
Returns the day portion of the specified date as a number.
GetHour ( <date> )
Returns the hour portion of the specified date as a number.
GetMinute ( <date> )
Returns the minute portion of the specified date as a number.
GetSecond ( <date> )
Returns the second portion of the specified date as a number.
ToTime ( <date> )
Returns the time_t value that represents the given date, which is the number of seconds elapsed since January 1, 1970 12:00 AM.
FromTime ( <seconds> )
This converts a time_t value back into a date.

 


Last modified 2008-09-22 04:27 PM
 

Powered by Plone

This site conforms to the following standards: