How to Automatically Set Issue Description from Email Content?

Hi everyone,

I need help with setting the description field in the Issue DocType using the message content of the Communication, which is typically an incoming email.

Here’s what I’m trying to do:

When a new Issue is created (via email), I want its description to be auto-filled with the email message (from the Communication entry).

I wrote the following server script with DocType Event = After Insert on the Issue DocType:

python

if not doc.description:
comm = frappe.get_all(
“Communication”,
filters={“reference_doctype”: “Issue”, “reference_name”: doc.name},
fields=[“content”],
order_by=“creation asc”,
limit=1
)
if comm and comm[0].content:
doc.db_set(“description”, comm[0].content)

But this doesn’t seem to work—description remains blank. I think the Communication record might not exist yet when this code runs.

Thanks in advance for your help!