TASK_TEMPLATE

Knowledgebase

TASK_TEMPLATE

Function Overview

TASK_TEMPLATE is a custom function that enables the creation of dynamic task templates by embedding cell references, URLs, or lookup dictionaries directly into your template text. When executed via the sidebar Run button, it converts the template into a JSON string that the back-end processes to paste the rendered output into a cell and, optionally, generate a Google Doc or text file.

Uses

  1. Generate personalized messages by inserting cell values into a greeting template.
  2. Aggregate content by embedding data from external URLs or documents.
  3. Implement lookup dictionaries to dynamically render parts of a template.
  4. Automate file creation by specifying output document or text file names.

Syntax and Parameters

=TASK_TEMPLATE(template, [output_doc_name], [output_textfile_name], [celladdress])

Parameter Data Type Required Description
template

string

Required The input template that contains text and placeholders (e.g.,

"Hello {A1}, welcome!"

).
output_doc_name

string

Optional The name for a new Google Doc. If provided, a new document is created with the rendered result and a hyperlink is added to the cell where the function is run.
output_textfile_name

string

Optional The name for a new text file. If specified, a new text file is created with the rendered output and a hyperlink is added to the sheet.
celladdress

string

Optional The cell address where the rendered output should be placed (e.g.,

"C1"

). If omitted, the function pastes the output in the cell immediately to the right.

Advanced Options

Output To Google Doc

When you include a non‑empty string for output_doc_name, the function creates a new Google Doc with the rendered output and places a hyperlink in the respective cell.

=TASK_TEMPLATE("Hello {A1}", "My Story")

Output As A Text File

Providing a name for output_textfile_name creates a text file with the rendered output and adds a hyperlink to this file in your sheet.

=TASK_TEMPLATE("Report data: {A1:A5,B1:C5}", "", "output.txt")

Specification Of Output Cell

You can override the default output location by explicitly setting the celladdress parameter.

=TASK_TEMPLATE("Summary for {A1}", "", "", "D2")

Examples

Example 1: Simple Greeting Template

This example demonstrates how to generate a personalized greeting using cell references.

=TASK_TEMPLATE("Hello {A1}, your score is {B1}.")

Expected output:
The placeholders

{A1}

and

{B1}

are replaced with the corresponding cell values, and the rendered message appears in the adjacent cell (or in the specified cell).

Example 2: Create A Report Google Doc

This example shows how to generate a Google Doc from a sales report template.

=TASK_TEMPLATE("Sales Report for {A1}:
Total Sales: {B1}", "Monthly Report")

Expected output:
The template is rendered using the values from A1 and B1. A new Google Doc named “Monthly Report” is created and a clickable hyperlink is added to your sheet.

Example 3: Output As Text File In Specific Cell

This example renders a template using a lookup dictionary and places the output starting at a designated cell.

=TASK_TEMPLATE("Data snapshot: {A1:A5,B1:C5}", "", "snapshot.txt", "E3")

Expected output:
A text file named “snapshot.txt” is created with the rendered content, and a hyperlink to this file is placed starting at cell E3.

Best Practices

  • Always use quoted strings for cell addresses and output names (e.g.,

    "C1"

    ).
  • Keep templates clear and simple to avoid overcomplicating placeholder replacements.
  • Test your templates with sample data before applying them to critical datasets.
  • Use distinct names for new Google Docs and text files to easily identify them later.
  • Rerun the function using the sidebar’s Run button whenever the source data changes.

Troubleshooting

Common Issue: Missing Required Parameter

If you encounter an error like "Missing required parameter: 'template'", ensure that the first parameter is not empty.

Common Issue: Invalid Output Cell Error

Double-check that the celladdress is enclosed in quotes and follows A1 notation (e.g.,

"C1"

).

Common Issue: Placeholders Not Replaced

Verify that the referenced cells exist and contain data, and that there are no formatting errors in your placeholder syntax.

Common Issue: Document/File Creation Problems

If a Google Doc or text file isn’t created, ensure you have the necessary permissions to create files in your designated Drive folders and that the file name is entered correctly.

Common Issue: JSON Or Run Button Errors

If the returned JSON string produces an error when the Run button is clicked, review the error message to identify which parameter may be misformatted or missing.

FAQ

Q: What types of placeholders can I use in my template?

A: You can use cell references (e.g.,

{A1}

), column-only references (e.g.,

{A}

for the current row), URLs (e.g.,

{https://www.example.com}

or with a format specifier like

{https://www.example.com|markdown}

), Google Doc IDs (e.g.,

{1d-oC-6Whej0jjdknMqw6r2WmqfdSLijS}

), and lookup dictionaries (e.g.,

{A1:A5,B1:C5}

).

Q: Do I Need To Run The Function Manually After Changing The Data?

A: Yes. Since TASK_TEMPLATE creates a JSON configuration, you need to click the Run button in the Sheet Workflows sidebar to re‑execute it.

Q: Can I Use TASK_TEMPLATE Without Creating A Google Doc Or Text File?

A: Certainly. Both output_doc_name and output_textfile_name are optional. If they are omitted, the rendered template is simply placed in the specified cell or in the cell immediately to the right by default.

Q: How Do I Choose Where The Output Is Placed?

A: Use the celladdress parameter to explicitly set the destination cell. If it’s omitted, the add-on automatically selects the cell to the right of where the function is called.

Q: What Happens If My Template Contains An Error?

A: An error message will indicate which parameter is missing or mis‑formatted. Review your template syntax to correct any mistakes in the placeholders.

Elisha

1 month ago

Categories
Features