Named Queries In Microsoft Templates (DOCX, PPTX, XLSX)
Use the correct square-bracket syntax for named query blocks and merge fields in DOCX and PPTX templates.
Use this page when your named query works in the HTML editor but needs DOCX or PPTX syntax.
The query logic stays the same.
The wrapping syntax changes.
Core rule
Wrap both the query block and the merge fields in square brackets.
Basic pattern
[{{!<lineitemsSOQL>
<queryname>TopLineItem</queryname>
<soql>
SELECT Name, TotalPrice
FROM OpportunityLineItem
WHERE OpportunityId = '{{!Opportunity.Id}}'
ORDER BY TotalPrice DESC
LIMIT 1
</soql>
</lineitemsSOQL>}}]
[{{!TopLineItem.Name}}]
[{{!TopLineItem.TotalPrice #,###.##}}]Use the same query name and field names you would use in HTML templates.
The only difference is the surrounding square brackets.
Use filter and offset
filter and offset work in DOCX and PPTX too.
Common fixes
Blank output: Confirm the field appears in
SELECTWrong row: Check
ORDER BYbefore usingoffsetFilter fails: Match
filter="1"to the<filter id>value exactlySyntax issue in DOCX or PPTX: Make sure both the query block and the merge field use square brackets
Keep going
Review Named Query Structure for the base tag and merge field rules
Review Named Query Working Examples for more reusable query patterns
Review How to: Advanced Data Retrieval with Named Queries for aggregates, filters, and offsets
Last updated
Was this helpful?

