Associate inbound email with existing ticket, don't create new ticket
Asked by Gamal Lear:

Hi there. We're in the process of migrating from Freshdesk to JSM Premium and will be migrating all our existing tickets across. As part of that migration process, we will put the Freshdesk ticket ID into a custom field on the issue within JSM, so we have a record. The challenge we have is that once we go live on JSM, if any customer sends an email on a ticket that was originally opened in Freshdesk, then the subject line will have the Freshdesk ticket ID in it, not the JSM issue key, meaning that JSM will consider it a new ticket, rather than a reply to an existing open ticket (that was migrated).

Is there any way of considering these emails as replies to the tickets that are open in JSM via the migration, through some sort of automation rule or similar? I had hoped we could look to match the presence of the FD ticket ID in the subject line with the same value in the custom field of the JSM issue and use that to identify the issue to associate the email with, but I'm not sure if that will work or if there's a better option: I imagine this must be a common challenge for businesses where it is not possible to duel run on 2 ticket systems (as some of our tickets remain open a long time).

Any help/suggestions gratefully received!


Answers:
author: Kris Dewachter
body: Hi [@Gamal Lear](/t5/user/viewprofilepage/user-id/5310321) ,

It happens that i'm currently working on a similar issue. I've solved this with a simple automation rule that is triggered once a new ticket is created in Jira.

The rule will try to retrieve the ticketnumber from the summary by using substring in a smartvalue. Ex. {{issue.summary.substringAfter("#")}} (in this example, the ticketnumber appears after the #-sign).

Then, i added a branch in my automation rule that finds the ticket by using a JQL

Once found, I add the content of the trigger issue as a comment to the existing ticket.

Then, I delete the trigger issue.

Hope this helps,

Best regards,

Kris

comments: author: Gamal Lear
body: Hi Kris, thanks so much for taking the time to share that, it certainly sounds like what we are looking for! Would you be kind enough to share a screenshot or two of the JQL and the rule step for adding the contents of the trigger issue as a comment on the existing ticket? Given it's working well for you, I'd love to replicate the exact approach and do some testing at this end.

Thanks again,

Gamal


author: Kris Dewachter
body: Hi [@Gamal Lear](/t5/user/viewprofilepage/user-id/5310321) ,

Sure. After the trigger, I use a "Create Variable" action to extract the ticketnumber from the "Summary" of the ticket. In this example, the ticketnumber appears after the #-sign.

![Screenshot 2024-03-28 at 16.36.25.png](https://community.atlassian.com/t5/image/serverpage/image-id/315173i4375D75EA4FCD354/image-dimensions/288x198?v=v2 "Screenshot 2024-03-28 at 16.36.25.png")

I also save the "Description" in a variable.

![Screenshot 2024-03-28 at 16.37.00.png](https://community.atlassian.com/t5/image/serverpage/image-id/315175iFE822B9E5DA44172/image-dimensions/296x192?v=v2 "Screenshot 2024-03-28 at 16.37.00.png")

Then I create a Branch and use a JQL command to retrieve the ticket. The JQL will be different in your case because you store the ticketnumber in a custom field.

![Screenshot 2024-03-28 at 16.40.25.png](https://community.atlassian.com/t5/image/serverpage/image-id/315178iDF0E742BBC4AB4E2/image-dimensions/312x390?v=v2 "Screenshot 2024-03-28 at 16.40.25.png")

![Screenshot 2024-03-28 at 16.42.11.png](https://community.atlassian.com/t5/image/serverpage/image-id/315179iC91DE6B68EE7B5E9/image-dimensions/338x223?v=v2 "Screenshot 2024-03-28 at 16.42.11.png")

And I use the "Add Comment" action to add the description as a comment to the ticket

![Screenshot 2024-03-28 at 16.43.16.png](https://community.atlassian.com/t5/image/serverpage/image-id/315180i722500C0B862C4C5/image-dimensions/305x233?v=v2 "Screenshot 2024-03-28 at 16.43.16.png")

Best regards,

Kris


author: Gamal Lear
body: Thanks again Kris, that's awesome. All makes complete sense. Just one final question if I may! In my situation, the email subject has the Freshdesk ticket ID that following the format \[#123456\] - so I want to extract the 123456. Substring can be used like you suggest but I end up with 123456\] - do you know the syntax to drop the trailing \] after the final digit?


author: Kris Dewachter
body: Hi [@Gamal Lear](/t5/user/viewprofilepage/user-id/5310321) ,

Please give the "substringBetween" option a try:

{{issue.summary.substringBetween("e","d")}}

Best regards,

Kris


author: Gamal Lear
body: Thanks Kris! That does seem to work but I've been struggling to get the JQL to parse. I've tried various operators as well as both numeric and short text field types for versions of the below, where *Grouptextfield* is the custom field on the ticket we want to find and *FDTicketID* is the variable that holds the Freshdesk ID extracted via the above substring:

![Screenshot 2024-04-02 084953.png](https://community.atlassian.com/t5/image/serverpage/image-id/315673i5CA87D5394BD6D5C/image-size/large?v=v2&px=999 "Screenshot 2024-04-02 084953.png")

No matter what I do, I get the error below - it must be a syntax error where it is not including the variable in what's being evaluated. Any ideas what I might be doing wrong?

![Screenshot 2024-04-02 084854.png](https://community.atlassian.com/t5/image/serverpage/image-id/315676i8C6CEC1DFAAB981A/image-size/large?v=v2&px=999 "Screenshot 2024-04-02 084854.png")

Gamal


author: Kris Dewachter
body: Hi [@Gamal Lear](/t5/user/viewprofilepage/user-id/5310321) ,

Your JQL seems valid.

Does your variable FDTicketID only contain the ticketnumber, or also something more? Have you tried displaying the value in the audit log of the automation rule ?

Best regards,

Kris


author: Gamal Lear
body: I managed to debug it and it appears to be working well! Top stuff, thanks for all your help Kris.


author: Kris Dewachter
body: Hi [@Gamal Lear](/t5/user/viewprofilepage/user-id/5310321) ,

Good to hear you got it working.

By clicking the green 'Accept Answer' button you can help other community members identifying helpful posts.

Thank you

Best regards,

Kris


author: Gamal Lear
body: Will do [@Kris Dewachter](/t5/user/viewprofilepage/user-id/4588367) - you don't happen to know how to delete the trigger issue, as opposed to the issue that is getting the contents of the variable added to it do you?


author: Kris Dewachter
body: Have you tried adding the "Delete Issue" action at the end of the automation rule, outside of the branch ?

![Screenshot 2024-04-02 at 20.25.33.png](https://community.atlassian.com/t5/image/serverpage/image-id/315851i46CAF519DDFBEABB/image-dimensions/278x348?v=v2 "Screenshot 2024-04-02 at 20.25.33.png")


author: Gamal Lear
body: Every day's a school day - yes, outside the branch does the business. I'm sorted now - thanks for the education! :-)


Tags: cloud

jira-service-management

jira-service-management-cloud