- 20 Aug 2024
- 1 Minute to read
- Print
- DarkLight
SDK: Text Merge Extensions
- Updated on 20 Aug 2024
- 1 Minute to read
- Print
- DarkLight
Overview
Decisions includes a number of built-in text merge fields like "Capitalize," "Lower," and "Insert Current Date." These merge fields can be used to dynamically manipulate strings or insert data from other sources into a Text Merge. Text merge extensions allow a user to write custom text merge logic to accomplish any type of merge desired.
Example
This example will demonstrate how to create a text merge that returns the length of a string.
- Download the Decisions SDK from Manage NuGet Packages and add the following using statements:
using DecisionsFramework.Design.Text; using DecisionsFramework.ServiceLayer.Services.ContextData; using DecisionsFramework.Utilities.Data;
- Have the class inherit from and implement AbstractStringFieldExtension.
When implementing this class, it includes two override methods: string GetMergeText and string Name.
The string returned by GetMergeText will be the string displayed at the run time of your Text Merge. The string returned by Name will be the name of the merge displayed at design time.
Below is an example implementation of string Name which will return the name of Get String Length.
public override string Name => "Get String Length";
This name of Get String Length will show in the Designer as shown below:
Below is an example implementation of the string GetMergeText method which will return the length of the string.
public override string GetMergeText(DataPair[] data)
{
string text = null;
object value;
if (DataUtilities.TryGetValue(data, TextField, out value))
{
text = Convert.ToString(value);
return text.Length.ToString();
}
else
{
return null;
}
}
Using this new Get String Length merge, the string's length will be returned as shown below: