Replace Text
Replaces text in a Google Docs document.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Document Id - The ID of the Google Docs document to replace text in.
- Text to Replace - The text to search for and replace.
- Replacement - The replacement text.
Options
- Search case-sensitive - Whether the search should be case-sensitive. Default is false.
- Replacement Type - The type of replacement to perform. Options are:
- Text - Replace with plain text
- Link - Replace with a hyperlink
How It Works
The Replace Text node integrates with Google Docs to find and replace text within a document. When executed, the node:
- Validates the provided inputs (Document Id, Text to Replace, Replacement)
- Connects to the specified Google Docs document
- Searches for all occurrences of the specified text
- Replaces the found text with the replacement text or link
- Updates the document with the replaced content
Requirements
- A valid Google Docs document ID
- Valid Google Docs credentials
- Valid text to search for and replace
- Valid Google Docs permissions to modify the document
Error Handling
The node will return specific errors in the following cases:
- Empty or invalid Document Id
- Empty or invalid Text to Replace
- Empty or invalid Replacement
- Google Docs service errors
- Insufficient permissions to modify the document
- No matching text found for replacement
Usage Notes
- The Document Id can be found in the URL of the Google Docs document
- When using the Link replacement type, the replacement text will be used as the URL for the hyperlink
- The Search case-sensitive option determines whether the search is case-sensitive
- All occurrences of the Text to Replace will be replaced with the Replacement text
- If no matches are found, an error will be returned
- The node supports both plain text replacement and hyperlink replacement
Practical Examples
Example 1: Replace Placeholder Text
Replace template placeholders with actual values:
Inputs:
- Document Id:
$.document_id - Text to Replace:
"{{CUSTOMER_NAME}}" - Replacement:
"John Smith"
Options:
- Search case-sensitive:
false - Replacement Type:
Text
Use Case: Template-based document generation with placeholders
Example 2: Update All Dates
Replace old dates with new ones throughout document:
Inputs:
- Text to Replace:
"2023" - Replacement:
"2024"
Result: All instances of "2023" become "2024"
Example 3: Convert Text to Links
Convert URLs in text to clickable links:
Inputs:
- Text to Replace:
"https://example.com" - Replacement:
"https://example.com"
Options:
- Replacement Type:
Link
Result: Plain text URL becomes a clickable hyperlink
Example 4: Replace Multiple Values in Loop
Replace multiple placeholders using a loop:
Workflow:
For Each placeholder in placeholders:
Replace Text:
Text to Replace: placeholder.key
Replacement: placeholder.value
Example Data:
{{NAME}}→"Jane Doe"{{DATE}}→"2024-01-15"{{AMOUNT}}→"$1,500"
Example 5: Case-Sensitive Replacement
Replace only exact case matches:
Inputs:
- Text to Replace:
"API" - Replacement:
"Application Programming Interface (API)"
Options:
- Search case-sensitive:
true
Result: Only "API" is replaced, not "api" or "Api"
Example 6: Reference Links
Convert document references to clickable links:
Inputs:
- Text to Replace:
"See Documentation" - Replacement:
"https://docs.company.com"
Options:
- Replacement Type:
Link
Result: "See Documentation" becomes a clickable link to the documentation
Tips for Effective Use
- Use placeholders - Design templates with
{{PLACEHOLDER}}syntax for easy replacement - Test case sensitivity - Decide if "Company", "company", and "COMPANY" should all match
- Verify before replacing - Read document first to confirm text exists
- Handle no matches - Use Continue On Error if some documents might not have the text
- Replace in order - For overlapping replacements, do them in the correct sequence
- Link formatting - When creating links, the displayed text stays the same, URL is added
- Batch replacements - Use arrays/loops to replace multiple values efficiently
Common Errors and Solutions
Error: "No matching text found for replacement"
Cause: The specified text doesn't exist in the document
Solution:
- Verify the exact text exists in the document
- Check spelling and spacing
- If case-sensitive is true, verify exact case matches
- Use Read Document first to verify content
- Enable Continue On Error if this is expected in some cases
Error: "Document ID cannot be empty"
Cause: Document ID is missing
Solution:
- Use Open Document or Create Document first
- Verify
$.document_idvariable is set - Check previous nodes executed successfully
Error: "Text to Replace cannot be empty"
Cause: Text to Replace input is empty
Solution:
- Provide a valid search string
- Check variable contains a value
- Ensure placeholder variable is populated
Error: "Replacement cannot be empty"
Cause: Replacement text is empty
Solution:
- Provide replacement text (can be empty string if intentional deletion)
- Verify variable has a value
- Use a space " " if you want to replace with blank
Error: "Failed to replace text" or "Failed to insert link"
Cause: API error or permission issue
Solution:
- Check account has write permission to document
- Verify document isn't view-only
- Try re-opening the document
- Check for API rate limits
Case sensitivity issues
Cause: Search case-sensitive setting doesn't match needs
Solution:
- Set to
falsefor case-insensitive matching (Company = company) - Set to
truefor exact case matching (Company ≠ company) - Consider the content of your documents when choosing
Integration Patterns
Pattern 1: Template Document Generation
Generate personalized documents from templates:
1. Create Document or Open Document (template)
↓
2. For Each field in customer_data:
Replace Text:
Text to Replace: field.placeholder
Replacement: field.value
↓
3. PDF Export (optional)
↓
4. Email or save document
Pattern 2: Bulk Document Updates
Update multiple documents with new information:
For Each document_url in document_list:
1. Open Document
↓
2. Replace Text (old value → new value)
↓
3. Log success
Pattern 3: Link Insertion
Add hyperlinks to documents:
1. Open Document
↓
2. Replace Text (company name → company website)
Replacement Type: Link
↓
3. Replace Text (product name → product page)
Replacement Type: Link
Pattern 4: Dynamic Content Update
Update reports with current data:
1. Fetch current data from database
↓
2. Open Document (report template)
↓
3. Replace Text ("{{TOTAL_SALES}}" → actual value)
↓
4. Replace Text ("{{DATE}}" → current date)
↓
5. Replace Text ("{{STATUS}}" → status value)
Pattern 5: Multi-Language Translation
Replace text sections with translations:
For Each section in translations:
Replace Text:
Text to Replace: section.english
Replacement: section.spanish
Advanced Use Cases
Conditional Replacements
Replace based on conditions:
Workflow:
// JavaScript node
if ($.status === "approved") {
$.replacement = "APPROVED ✓";
} else {
$.replacement = "PENDING";
}
Then use Replace Text with $.replacement
Nested Placeholders
Handle complex template structures:
First Pass:
- Replace
{{SECTION_A}}with detailed content
Second Pass:
- Replace placeholders within the inserted content
URL Construction
Build and insert dynamic URLs:
Inputs:
- Text to Replace:
"View Report" - Replacement:
"https://reports.company.com/id=" + $.report_id
Options:
- Replacement Type:
Link
Replacement Type Details
Text Replacement
- Replaces matched text with plain text
- Preserves existing formatting
- Simple and fast
- Use for: Data updates, content changes, corrections
Link Replacement
- Replaces matched text with a hyperlink
- Displayed text stays the same
- URL is added as link destination
- Text becomes clickable
- Use for: Adding references, creating navigation, linking resources
Example:
- Original:
"Contact Support" - After Link Replacement:
"Contact Support"(but now clickable, links to support URL)