Klevr Product Documentation logo

Email Template Find and Replace

Custom API to find and replace text in email templates.

Feature Overview

Email templates out of the box only allows for a narrow scope of slugs based on the related record. With Flow it is possible to retrieve a lot of related record info, and even unrelated information as well, that we would like to add to an email template. This utility was first developed by the HMRI implementation team and was deemed to be useful in other project too, so it got promoted to a klevr utility.

Design Details and Usage

The usage of the klevr_GetTemplateWithCustomValues Custom API Function is straight forward, but you have to keep in mind that it replaces the out of the box functionality, and does not work in conjunction with it, therefore out of the box slugs will not be replaced, unless you specify them and pass a replacement value for them as well.

The function is implemented as an unbound Custom API call and can be invoked from a Power Automate Flow, or any custom code. To use it, you have to supply a JSON object with find and replace values (see sample below) as well as a template GUID. The function will then retrieve the template subject and body, replace all the given values in the JSON, and return the subject and body as return parameters.

NameTypeDescription
klevr_GetTemplateWithCustomValuesFunctionThe name of the Custom API function
klevr_KeyValuePairsInput Parametera stringified JSON object of find and replace values. See example below
klevr_TemplateIdInput Parametera GUID representing the ID of the template to use
klevr_ResponseBodyOutput ParameterThe resulting body text with the replacements applied
klevr_ResponseSubjectOutput ParameterThe resulting subject text with the replacements applied

JSON Example: the JSON object should consist of attributes that represent the text to find, with values representing the text to replace, e.g.

{ 
   "Find This Text": "Replace it with this text",
   "%Fullname%", "Bob Saget"
 }

Your template should then have these values in its text, e.g.

Dear %Fullname%,

If you can Find This Text, you are awesome.

The end result would be:

Dear Bob Saget,

If you can Replace it with this text, you are awesome.

It is a good idea to add some special characters around your find text, so that it won't be mistaken for actual content in your template. You can use anything for this purpose, as long as your JSON object and email template match, e.g. #Fullname# or ~~Fullname~~ rather than just Fullname.

Last updated on