Skip to content

Make InstantiateTemplate merge the template instead of returning an empty e-mail - #351

Open
Bircck wants to merge 1 commit into
worktree-send-email-from-templatefrom
instantiate-template-render
Open

Bircck wants to merge 1 commit into
worktree-send-email-from-templatefrom
instantiate-template-render

Conversation

@Bircck

@Bircck Bircck commented Sep 2, 2026

Copy link
Copy Markdown

Stacked on #331 — targets worktree-send-email-from-template for the shared renderer. Merge #331 first; this rebases onto master afterwards.

InstantiateTemplateRequestHandler returned a bare new Entity("email"). Anything reading the instantiated subject or body got nothing, and calls naming records that don't exist succeeded silently.

What changed

The retrieve → validate → render sequence is now shared with SendEmailFromTemplate through EmailTemplateInstantiator. The two messages differ only in what they do with the merged content: InstantiateTemplate returns it, SendEmailFromTemplate copies it onto the target and creates + sends.

ObjectType guards now use Dataverse's messages (Required field 'ObjectType' is missing… / Expected non-empty string.) rather than ObjectType is missing.

Verification

InstantiateTemplate persists nothing, so it was safe to call directly against a live org. Every behaviour below is asserted in the tests:

Live org
Response one email, attributes subject + description only, empty id
Merge context the target record and the calling user
Body wrapped in the same HTML envelope SendEmailFromTemplate returns
Missing template or record template With Id = … Does Not Exist
templatetypecode mismatch Template type is incorrect for given objectType 2 != 1 template.templatetypecode, raised before the record lookup

The three pre-existing tests passed random GUIDs for TemplateId/ObjectId, which the stub accepted; they now use real records. Five tests total, 680 in the suite, net462 builds clean.

https://claude.ai/code/session_01YWUbYsznntsbtkmxHDcvaa

The handler returned a bare `new Entity("email")`, so anything reading the
instantiated subject or body got nothing, and calls naming records that do not
exist succeeded silently.

The retrieve/validate/render sequence is now shared with SendEmailFromTemplate
through EmailTemplateInstantiator; the two messages differ only in what they do
with the merged content. InstantiateTemplate returns it, SendEmailFromTemplate
copies it onto the target and creates + sends.

Verified against a live org (InstantiateTemplate persists nothing, so it is safe
to call directly): the response carries subject and description only, with the
body in the same HTML envelope SendEmailFromTemplate returns; a missing template
or record and a templatetypecode mismatch each fault, the mismatch taking
precedence over the record lookup. The ObjectType guards now use Dataverse's own
messages instead of "ObjectType is missing".

680 tests pass, net462 builds clean.

Claude-Session: https://claude.ai/code/session_01YWUbYsznntsbtkmxHDcvaa
@Bircck
Bircck force-pushed the instantiate-template-render branch from 3da19ff to 93d3b10 Compare September 3, 2026 10:48
@Bircck Bircck changed the title Make InstantiateTemplate merge the template instead of returning an empty email Make InstantiateTemplate merge the template instead of returning an empty e-mail Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant