Search and Replace
The Search and Replace Pipe will allow you to pass a text value and replace defined search values with new values.
The Search and Replace Pipe will come in handy when you need to replace defined search values with new defined values. For instance, you can utilize the Search and Replace Pipe to replace every "company_name" placeholder text within your database with the company name of the given record.
While this pipe may seem similar to using a text formula, there are several differences to note:
- This will not update when the text formula value changes, rather it will remain static in the database
- The search values can be dynamic and originate from other fields, which can not be done in Text Formulas
- The search will replace all instances of the searched value, making it easier and more reliable than text formulas
Let's demonstrate the Search and Replace Pipe with another example. Say we want to find every text value of "Hi my name is firstName lastName and I come from city." and replace the "firstName", "lastName", and "City" values with new values pulled from our database records.
First, we would like to the pass the value of:
Hi my name is firstName lastName and I come from city.
And then create searchable parameters with new values. In this case we will create 3 parameters:
- firstName
- lastName
- city
When we run the pipe, we would like for the new values to be passed and for the sentence to be updated with the new values.
To accomplish this, we will first build the request and then create the parameters. Let's walk through both of these steps below.
Build the Request
First, we will build the request parameters as JSON values. The key is what we should search for and the value is what it should be replaced with.
For instance: { "firstName" : "John" }
will replace the text "firstName" with "John".
However, since we want to determine the first name, last name, and city based on the records we're working with, we'll create dynamic parameter values, such as: {"firstName" : "{firstName}"}
Create Parameters
Then, for whichever values you'll be supplying dynamically, create those parameters in the Parameters tab.
As you can see in the test below, when we pass new dynamic values the original sentence is replaced with the appropriate results.
You can now use the Search and Replace Pipe anywhere where Pipes are accessible.
For instance, you can utilize this pipe by adding it as a Table Rule:
On the live app, this table rule will result as such:
We'd love to hear your feedback.