Skip to content

Automations

An Automation is a workflow of business process actions, executed for each incoming message from the configured Message Source. Automations can contain any number of Actions. Automations themselves can Call other Automations and the returned value from the called Automation can be assigned to a variable in the parent.

To create an Automation click the New Automation button on the ThinkAutomation Studio ribbon.

Variable Replacements

All Actions that have parameters allow you to use %variable% replacements.

This means you can specify a ThinkAutomation variable, extracted field, list, built-in variable, solution constant or global constant as the parameter (or part of) that will be replaced at execution time with the value of the variable. Variable names must be enclosed with % symbols.

For example, outgoing emails can contain values extracted from the incoming message by simply inserting %variablename% (where 'variablename' is the name of your variable) into the email text (or any other setting):

Dear %Name%,

We have received your enquiry %Msg_Subject%. This has been assigned ticket number %TicketNumber%.

Another example: The Process Attachments action allows you save attachments from the incoming message to folders on your system. If you had created a variable called OrderNumber you could save the attachment as:

C:\Orders\order%OrderNumber%.pdf

If %OrderNumber% contained '1234' then the file would be saved as C:\Orders\order1234.pdf.

Built-In Message Variables

In addition to extracted fields and variables that you create in your Automation, you can also use any of the following built-in message variables. These automatically contain values related to the current message:

Name Details
%Msg_Body% The incoming message body in plain text format. If the incoming message is HTML only, then the plain text body will be created from the HTML with all tags removed.
%Msg_Html% The incoming message HTML body.
%Msg_Mime% The full mime text of the incoming message.
%Msg_Json% A Json document representing the incoming message. See: Built In Json Variables
%Msg_ExtractedFieldsJson% A Json document containing all extracted fields names and their values. See: Built In Json Variables
%Msg_Text% The mime text without headers.
%Msg_Subject% The incoming message subject.
%Msg_LastReplyBody% If the incoming message is a reply, this variable returns the last reply text. Quoted text and previous replies are removed where possible. The %Msg_Body% will be returned if the incoming message contains no replies or quoted text.
%Msg_Digest% The first 750 characters of the last reply body (with blank lines & whitespace trimmed).
%Msg_To% The 'to' address.
%Msg_ToWithNames% The 'to' address including names (if available).
%Msg_From% The 'from' address.
%Msg_FromEmail% The 'from' address without the name portion.
%Msg_FromName% The 'from' address name portion only (if available).
%Msg_FromIP% The IP address of the sender (extracted from the RemoteHost or Received header).
%Msg_CC%, %Msg_CCWithNames% The 'cc' address.
%Msg_BCC%, %Msg_BCCWithNames% The 'bcc' address.
%Msg_ReplyTo% The 'reply to' address.
%Msg_References% The 'references' header.
%Msg_Return-Path% The 'return-path' header.
%Msg_Sender% The 'sender' header.
%Msg_Date% The date and time of the message.
%Msg_Size% The total size of the message including attachments.
%Msg_Importance% The 'X-Priority' header, either HIGH,LOW or NORMAL.
%Msg_Sensitivity% The 'sensitivity' header.
%Msg_BounceType% The bounce type. See: Bounce Processing
%Msg_BounceAddress% The bounce address. See: Bounce Processing
%Msg_Headers% The full headers section of the mime text.
%Msg_Attachments% Attachment file names (separated with CrLf).
%Msg_AttachmentsInLine% Inline attachment file names (separated with CrLf).
%Msg_AttachmentCount% The number of attachments.
%Msg_AttachmentInlineCount% The number of inline attachments.
%Msg_AttachmentsSavedTo% Attachment paths (separated with CrLf). During Automation processing each attachment is saved to a temporary location. The saved to path will be updated if the Process Attachments action is used to save the attachment to a new location.
%Msg_AttachmentsInlineSavedTo% Inline attachment paths (separated with CrLf).
%Msg_AttachmentListWithSizes% A string containing all attachment file names & sizes separated by commas eg: 'document1.pdf (2mb), document2.pdf (500kb)'
%Msg_CharSet% The character set of the incoming message.
%Msg_MessageId% The unique message identifier from the Message Source.
%Msg_MessageStoreId% The unique id assigned to the message by ThinkAutomation and used as a unique key in the Message Store database.
%Msg_ConversationId% A hash of the From & To email addresses (sorted) and Subject. This provides a key that matches other message store messages from/to, or to/from the same email addresses and subject.
%Msg_WordIndex% Unique keywords extracted from the message body (comma separated excluding common words).
%Msg_WordIndexSorted% Unique keywords sorted by word count (highest first).
%Msg_WordIndexWithCount% Unique keywords with word count.
%Msg_WordIndexWithCountSorted% Unique keywords with word count sorted (highest first).
%Msg_ValidationUrl% A link to the user response web page for the current message. Used by the Wait For User Response action.
%Msg_ResultsUrl% A link to the Automation return value served via the Web API.
%Msg_ViewUrl% A secure hashed link to a web page showing the current message served via the Web API.
%Msg_ViewUrlLocal% A secure hashed link to a web page showing the current message served locally.
%Msg_WebCallbackUrl% A link to a custom webhook callback for the current message. Used by the Wait For Webhook action.
%Msg_SignatureJson% A Json document representing contact information extracted the email footer (signature). See: Extract Email Signature

You can extract other email headers using the Set Variable action with the Extract Header operation or the Extract Field action with the Extract From set to %Msg_Headers%.

Bounce And Automatic Reply Processing

ThinkAutomation can recognize a variety of bounced email, automatic replies and unsubscribe replies. If the incoming message is detected as a bounce, automatic reply or unsubscribe the %Msg_BounceType% built-in variable will contain the reason. The %Msg_BounceAddress% will contain the bounced email address.

The %Msg_BounceType% will contain one of the following:

Value Details
Hard Bounce The email could not be delivered.
Soft Bounce A temporary condition exists causing the email delivery to fail.
General Bounce Could not determine if it is a soft or hard bounce.
Blocked A bounce occurred because the sender was blocked.
Auto-Reply/Out-Of-Office An automated auto-reply or out-of-office notification.
Transient Message Such as 'Delivery Status / No Action Required'.
Subscribe Request A 'subscribe' request.
Unsubscribe Request An 'unsubscribe' request.
Virus Notification The email was bounced due to virus.
Suspected Bounce A suspected bounce but no other information available.
Challenge/Response Auto-response sent by SPAM detector where only verified email address is accepted.
Address Change Notification
Relayed Message
Abuse Feedback Report

The %Msg_BounceType% variable will be blank if the message is not a bounce/auto-reply.

Solution Constants

You can also create Solution Constants. These are solution-wide constants that can be used as %variable% replacements on any Automation within a Solution. To create Solution Constants click the Edit Solution button on the ThinkAutomation Studio Explorer ribbon.

You can then specify any number of Constant Name and Constant Value pairs.

For example: If you create a solution constant with name 'VatNumber' and value 'GB12345678'. If you use %VatNumber% on any Action property on any Automation within the Solution, the value 'GB12345678' will be replaced when messages are processed.

Global Constants

Global Constants are global to all Automations on all Solutions. To create Global Constants use the Server Settings - Global Constants.

System Variables

A number of built-in system variables can also be used:

Name Details
%Date% The current date.
%DateYesterday% Yesterdays date.
%Time% The current local time.
%Hour% The current local time hour number.
%Minute% The current local time minute number.
%Year% The current year.
%DateTime% The current local date & time.
%DateTimeUtc% The current UTC date & time.
%SQLDate% The current date in yyyy-mm-dd format
%SQLDateYesterday% Yesterdays date in yyyy-mm-dd format.
%SQLDateTime% The current local date & time in yyyy-mm-dd hh🇲🇲ss format.
%SQLDateTimeUtc% The current UTC date & time in yyyy-mm-dd hh🇲🇲ss format.
%UnixTimeStamp% The current local date & time in Unix timestamp format (eg: 1676283187).
%UnixTimeStampUtc% The current UTC date & time in Unix timestamp format (eg: 1676283187).
%Timer% The number of elapsed seconds and milliseconds since midnight (eg: 51812.5037012).
%DayNumber% The current day of the month number (1-31).
%DayOfWeek% The current day of the week name.
%WeekdayNumber% The current day of the week number (1=Sunday, 2=Monday etc.).
%MonthNumber% The current month number (1-12).
%MonthName% The current month name.
%LastErrorText% This will contain a description of the last error from an action that has failed for some reason. This will be blank if no error has occurred.
%LastActionExecutionMs% This will contain the number of milliseconds the previous (non-comment) action took to execute.
%FreeDiskSpace% The current system drive free space in bytes.
%Root% The solution root folder. Corresponds to: ProgramData\Parker Software\ThinkAutomation.NET\%SolutionName%\
%AutomationLog% The current Automation execution log for the message.
%MessageSourceName% The name of the Message Source for the current message.
%MessageSourceType% The type of Message Source for the current message. This will be one of: Email, Database, File, WebForm, WebChat, SMS, Http, Azure, Graph, Static or API.
%AutomationName% The name of the Automation executing for the current message.
%AutomationId% The id of the Automation executing for the current message.
%SolutionName% The name of the Solution for the current message.
%SolutionId% The id of the Solution for the current message.
%SolutionEmail% The email address assigned to the Solution.
%SolutionContact% The contact name assigned to the Solution.
%CR% A carriage return character.
%LF% A line feed character.
%CRLF% A carriage return and line feed.
%TAB% A tab character.
%DB_Null% A null value. This can be used on database update action parameter values to specify a null value. Will be replaced with a blank string when used anywhere else.

You can also create your own constants for each Solution. See the Constants grid on the Solution Properties page. These Constants can be used on any Automation within the Solution.

The Root Folder

The %Root% system variable will contain a folder path to:

\ProgramData\Parker Software\ThinkAutomation.NET\%SolutionName%\

For example, if your solution name is 'Orders' and your system drive is 'C:\' then %Root% will contain:

C:\Program Data\Parker Software\ThinkAutomation.NET\Orders\

The %Root% variable replacement is useful for any Actions that need to save files locally. ThinkAutomation ensures that the folder exists and the ThinkAutomation Message Processor service will always have access to it.

For example: If using the Create Document action to create a PDF document you can set the Save To property of this action to %Root%.

InLine Functions

The variable replacement %func% can be used to execute a number of inline functions. Inline functions provide shortcuts to some common operations. The function will be executed and the returned value replaced. InLine functions can be used inside any action entry as with regular %variable% replacements.

The format of inline functions is: %func%:FunctionName(Value[,parameter][,parameter])

The value & parameters can be any fixed text or a %variable% replacement. If a parameter value contains brackets (), spaces or commas then it should be enclosed in quotes.

For example, in the text:

Dear %func%:ToProperCase(%fullname%),

If the fullname variable was set to 'alice bob' - when replaced the text would be:

Dear Alice Bob,

The following functions can be used:

Function Details
Upper(value) Converts the value to uppercase.
Lower(value) Converts the value to lowercase.
ToProperCase(value) Capitalizes each word in value.
Right(value,count) Returns the rightmost count characters in value.
Left(value,count) Returns the leftmost count characters in value.
IndexOf(value,searchtext) Returns the character position where searchtext occurs in the value.
Clean(value) Returns the cleaned version of value. All control characters are removed.
PlainText(value) Returns the plaintext version of value. If value contains HTML then all HTML tags are removed.
Html(value) Returns the value as is - without any HTML encoding. Useful when embedding %variables% in HTML email content where the %variable% content is already html.
Trim(value) Returns the trimmed version of value.
Line(value,linenumber) Returns the specified line of text if value contains multiple lines. Line numbers start at 1.
RemoveWhiteSpace(value) Returns value with all repeated space and control characters removed.
Truncate(value,count) Returns value truncated to a maximum length of count.
TruncateWithEllipsis(value,count) Returns value truncated to a maximum length of count with ellipsis characters at the end.
SubString(value,start [,number]) Returns the substring of value starting at position specified in start (zero based). If number is specified then the number of characters from the start position is returned, otherwise the characters from start until the end of the value are returned.
Replace(value,find,replacewith) Returns the value with the find parameter replaced with the replacewith parameter.
PadLeft(value,characters) Returns the value padded with spaces to the left if required to reach the total number of characters.
PadRight(value,characters) Returns the value padded with spaces to the right if required to reach the total number of characters.
Format(value, formatstring) Returns the formatted value using the formatstring. Formatstring can be any .NET format string.
Length(value) Returns the number of characters contain in the value.
Lines(value) Returns the number of lines of text contained in value.
EmailAddress(value) Returns the first email address found in value.
Url(value) Returns the first URL found in value.
Base64Encode(value) Returns the base64 encoded version of value.
Base64Decode(value) Returns the text value of the base64 encoded value.
URLEncode(value) Returns the URL encoded version of value.
URLDecode(value) Returns the text value of the URL encoded value.
DateAdd(value,interval,number) Returns a date with number of days, months, seconds or years added. The interval should be s=seconds,n=minutes,h=hours,d=day,yyyy=years.
DateDiff(interval,date1,date2) Returns a numeric value for the interval between date1 and date2. The interval should be s=seconds,n=minutes,h=hours,d=days,ww=weeks,yyyy=years.
Day(value) Returns the day number if value is a date.
Month(value) Returns the month number if value is a date.
MonthName(value) Returns the month name if value is a date.
Year(value) Returns the year number if value is a date.
HyperLink(value,linktext) Returns a HTML ref. The first URL or email address found in value will be used for the link URL. The linktext parameter will be used for the hyperlink text if specified.
PlainTextToHTML(value) Returns HTML from plaintext. Converts all line-feed characters to
, encodes special characters and encloses any URLS or email addresses in tags.
JsonValue(value,path) Returns a specific Json path value if value is Json text.
CSVValue(value,row,col) Returns a specific row/column value if value is CSV text (assumes CSV data has no column headers). Row and column numbers start at 1.
CSVWithHeadersValue(value,row,col) Returns a specific row/column value if value is CSV text (assumes CSV data has column headers). Row and column numbers start at 1.

Format Examples:

Order Date: %func%:Format(%Msg_Date%,U) :

replaced the text would be:

Order Date: 09 November 2020 09:00:00 :

If a parameter includes a comma you need to enclose it in quotes. Eg:

Order Date: %func%:Format(%Msg_Date%,"hh:mm tt, ddd-MM-MMM yyyy gg") :

Would be:

09:00 AM, Mon-11-Nov 2020 A.D.

Numeric Format

The Price Is: %func%:Format(%Price%,C)

replaced text would be:

The Price Is: £1234.56

Json Extract Example

You can use the %func%:JsonValue inline function to extract a specific Json path value. For example, if you have a variable called 'AddressJson' set to:

{ 
  "employee": { 
    "name":    "John",  
    "salary":   56000,  
    "married":  true 
   } 
} 

You could use the inline function such as:

Dear %func%:JsonValue(%AddressJson%,employee.name),

At runtime the replaced text would be:

Dear John,

For Json arrays, such as:

["Ford", "BMW", "Fiat"]

You can access an array item directly:

First item %func%:JsonValue(%Json%,[0]) or Second item %func%:JsonValue(%Json%,[1])

or

{
    "employees":["John", "Anna", "Peter"]
}

Second employee %func%:JsonValue(%Json%,employees[1])

Note: JsonValue uses JsonPath notation. Eg: object.subobject.array[0].name

CSV Extract Example

You can use the %func%:CSVValue inline function to extract a specific row/column value from CSV data. For example, if you have a variable called 'LineItem' set to:

1,ABC,Product 1,100.12
2.DEF,Product 2,200.13

You could use the inline funcion:

The price is %func%:CSVValue(%LineItem%,2,4)

At runtime the replaced text would be:

The price is 200.13

Row and column numbers start at 1. If your CSV data contained column headers you would use the CSVWithHeadersValue() function.