Writing an Expression Script

An expression script is used in the Fields Mapping Dialog when a column value needs to be mapped not simply to a source column but to a value retrieved after calculation. Alternatively, Mapping functions, or rules, can be used to define a rule which applies to all source-target pairs which meet the conditions specified in the rule.

Expression scripts can use:

  • User functions defined in a global script

  • EITHER standard C# library functions or standard Microsoft VB.NET library functions. The default language for new expression scripts is C#, but the language can be changed for all scripts associated with a metadata in the Global Script Editor available from the metadata right mouse button menu in the Metadata Explorer.

To set up a mapping to an expression:

  1. In the Replication Properties dialog, or in the Replication wizard, open the Fields Mapping dialog.

  2. Select a target field in the list and choose the Map to Expression option from the right mouse button menu.

  3. In the Expression Generator, type your expression or build it by expanding the tree to select items. The default language for expressions in C#, but you can change the language to VB.NET for ALL scripts associated with the metadata using the Global Script Editor.
    Functions defined in a global script are available from the User Functions node in the tree.

  4. If you are using C#, to use a function already defined in a global script (or one of the Predefined global script functions, precede the function name with "GlobalScript." to identify the class where the function is defined:

GlobalScript.AddLog("The current record has been inserted: " + s, 0);
  1. To refer to source fields in an expression script, indicate the field between square brackets, with no quotes. For example, to refer to the field ”EmployeeID” in the source table, use the syntax [EmployeeID].

  2. Click OK to close the Expression Generator and complete your expression.

Related Topics
Global Script Functions

Global Script Editor
Writing a Global Script

Writing Scripts