Macro expressions¶
Macros insert and format data anywhere in a component's settings: message fields, dates, counters, stored variables and decrypted secrets.
Syntax¶
A macro is written in braces, with no spaces. It has up to three parts separated by |: a function, optional conversion codes, and an optional length.
(x)is the function's argument and[start,length]takes part of the result. Both are optional.- Separate several conversion codes with a semicolon. They run left to right.
- Write characters you can't type, or that have a meaning in the syntax (comma, semicolon, tab), as their ASCII code in angle brackets:
<9>is a tab,<13><10>is a line break.
Examples, for the message 100,Test Name,123 Test Street,1736 with a comma separator:
| Macro | Result |
|---|---|
{Data(2)} |
Test Name |
{Data(2)[0,4]} |
Test |
{Data(2)\|Replace(e,a);Upcase} |
TAST NAMA |
{Data(4)\|Lf0\|-10} |
0000001736 |
{Data(4)\|Lf0\|10} |
1736000000 |
The length pads or cuts the result to that many characters. A negative length fills on the left; a positive length fills on the right.
Functions¶
| Function | Syntax | Returns |
|---|---|---|
| Data | {Data(n)}, {Data} |
Field n of the current message, split on the component's FieldSeparator. Numbering starts at 1: {Data(1)} is the first field. {Data} is the whole message. |
| DateTime | {DateTime(format)} or {DateTime\|format} |
The current date and time in the given format (codes below). Both forms work. |
| Counter | {Counter(name)} |
The next value of the named counter |
| MessageCount | {MessageCount} |
The number of messages in the current message queue |
| Variable | {Name} |
A value from the Common Store or Message Store |
| Constant | {ABCD} |
If no store entry has that name, the name itself (ABCD) |
| Decrypt | {Decrypt(value)} |
A value encrypted with the Data Encryptor, decrypted |
Conversion codes¶
| Code | What it does | Example |
|---|---|---|
Upcase (or Ucase), Lcase |
Upper or lower case | john → JOHN |
Field(sep,pos) |
Splits on a separator and returns one element (empty if the separator isn't there) | ABC*DEF*GHI with Field(*,3) → GHI |
FieldIf(sep,pos) |
Like Field, but returns the original value if the separator isn't there | |
Replace(old,new) |
Replaces every occurrence | This is a test with Replace(i,o) → Thos os a test |
Num, Alpha |
Keeps only digits, or only letters | 20GBP2001 → 202001 / GBP |
Sq |
Encloses in single quotes | abc → 'abc' |
Lf0 |
Fills with zeros to the length given | See examples above |
Lfill(n), Lfill(c,n) |
Left-fills with spaces, or with character c, to length n | |
Rfill(n), Rfill(c,n) |
Right-fills the same way | |
Add(n) |
Adds field n of the current message (not the number n) | {Data(3)\|Add(5)} on 100,300,200,700,123 → 323 |
Mul(n), Div(n) |
Multiplies or divides by n | Mul(2) on 50 → 100 |
Mul(n,sep), Div(n,sep) |
Splits on sep and multiplies or divides each element | |
Mod(div,mod) |
Modulo | |
Abs, Abs(sep) |
Absolute value, or of each element | -123*456 with Abs(*) → 123*456 |
NumberFmt(code) |
Formats a number (codes below) | |
Rfcd(code) |
Number format with a C prefix for positive and D for negative values |
|
DtRev |
Date to yyyy/mm/dd |
|
++ |
Adds 1 to a Common Store variable | {Cnt\|++} |
Number formats¶
| Code | 1234.5 becomes | Code | 1234.5 becomes |
|---|---|---|---|
N |
1,234.50 |
F |
1234.50 |
N3 |
1,234.500 |
F0 |
1234 |
C |
Currency in the server's regional format | F3 |
1234.500 |
P |
123,450.00% |
E |
1.234500E+003 |
Date and time formats¶
Combine codes with any non-numeric separator, for example {DateTime(yyyy-MM-dd hh:mm:ss)}. Results below are for Monday 15 January 2004, 07:48:27.
| Code | Result | Code | Result |
|---|---|---|---|
yyyy / yy |
2004 / 04 | hh |
07 |
MMMM / MMM / MM |
January / Jan / 01 | mm |
48 |
dddd / ddd / dd |
Monday / Mon / 15 | ss |
27 |
d / D |
Regional short / long date | tt |
AM |
Y |
January 2004 | t / T |
Regional short / long time |
Month (MM) is upper case and minutes (mm) lower case.
Test a macro before you deploy¶
- Press Shift + F7 to open the Macro Evaluator.
- Enter the macro in Evaluation String, the separator in Evaluation Separator (comma by default) and a sample message in Evaluation Data. You can paste a message from the Logging tab.
- Select Evaluate and check the result.