This article will show how specific text data from an email can be extracted for use in a database query. This is achieved by using variables and a General tool called Parse Text.
By using rules and parameters this tool can extract specific text from a variable which has been placed in a step. For example a rule is used to ‘extract text between [Point A] and [Point B]’. Point A and B are parameters which are defined by the user when creating the rule.
The data is then mapped to other variables for use in further steps, such as a query step.
Example: A variable holds the contents of an email message body, only a specific word is required from the email so it can be used in the query.
In the mapping field of the Email Trigger (SMTP) event tool, the picture above shows 3 variables. 2 of which are being used by the current Email Trigger (SMTP) step to store information about the sender’s email address and the main body of the email.
The 3rd variable remains unmapped and is the one going to be used by the Parse Text tool to map data to by using the text stored in the MessageBody variable. The variable can then be used by a database query.
Using the Parse Text tool
- From the task browser under General tools drag and drop the Parse Text tool into the task planner. This will automatically open the General tab of the tool.
- Provide an appropriate name and description
The Main tab is used to create rules that are applied to a variable so specific information can be extracted. Each rule can output the information to another variable.
Data – The variable containing the textual data to be used by the tool is dragged and dropped into this field from the Task Browser.
Rules – Rules are used to define how the text is extracted from a variable by using parameters. This field displays all rules in use. Rules are processed in the order in which they are displayed. Using the up and down arrows their positioning can be changed. Rules can be added, edited and removed here.
- Using the Task Browser drag and drop the variable containing the information to have text extracted from into the Data field.
- A rule must now be created to specify how text is extracted. Select Add which will display the following:
Name – A name for the rule
Type – Provides a drop down list with multiple options for exacting text.
Parameters – Displays the ‘rule type’ parameters in use. A parameter is defined by manually inserting text into the Value column, this will provide the location of where text is extracted from.
Variable output – The new variable to have the extracted text mapped to.Remove leading spaces – Removes any white spaces included at the beginning of the extracted text.
Remove trailing spaces – Removes any white spaces included at the end of the extracted text.
Remove CR and LF – Removes any carriage returns or line characters that may be included in the extracted text.
- Select a ‘rule type’ from the drop down list.
- In the Parameters field manually insert text in to the Value column, this will provide the specifics of where text is extracted from.
- Select a variable to output the text to from the Variable output drop down list.
- If required tick any 3 of the ‘Remove…’ tick boxes or all of them. This removes any accidental or additional spaces and carriage returns that might be present within the set parameter.
- Once complete select OK to close. The new rule will now appear in the Rules table. The extracted text, a key word, is mapped to the output variable ready to be used by the query step.Note: This example uses the rule Extract after [C] to the end of line. This extracts the text after the first occurrence of a specified word, in this case [ProductInterest:] and will continue to extract text until the end of the line. So, any text that occurs after ProductInterest: will be extracted.
The Parse Text tool has now been configured.
To read about tasks which make use of this tool see: