Jira Service Management automation rule - parse webhook request body for special characters

Drew Nedderman
Contributor
July 9, 2024

I have a Jira Service Management automation rule that was working as expected until a user filled out a form with special characters in the data.

I'm taking a new ticket from a service project and copying some data to a new Trello card.

The webhook action's request body looks like this:

{

"name": "{{issue.summary}}", "desc": "**Name:** {{issue.summary}}\n\n**Job Title:** {{issue.Job title}}\n\n**Team:** {{issue.New team}}\n\n**Manager**: {{issue.Manager.displayName}}\n\n**Role Type**: {{issue.Employment type}}\n\n**Start Date**: {{issue.Start date.fullDate}}\n\n**Desired Office Location:** {{issue.Employee location}}\n\n**Machine Type:** {{issue.Machine Type}}\n\n**Tech Needs:** {{issue.Tech Needs}}\n\n**Additional Comments:** {{issue.description.replace("\n"," \\n")}}\n\n**Attachments:**\n\n{{#triggerIssue.attachment}}\n\n* {{filename}}: {{content}}{{/}}\n\n**Jira Ticket:** {{triggerIssue.url}}", "idList": "MyListID", "idMembers": "member1,member2", "idCardSource""MySourceCard", "keepFromSource": "checklists" }

 

The results are like this:

{ "name": ""firstname "nickname" lastname"", "desc": "**Name:** "firstname "nickname" lastname"\n\n**Job Title:** job role\n\n**Team:** Client Services\n\n**Manager**: manager name\n\n**Role Type**: Full Time\n\n**Start Date**: full date\n\n**Desired Office Location:** Remote\n\n**Machine Type:** computer type\n\n**Tech Needs:** \n\n**Additional Comments:** Some comments \n \nEmail: email link \nPhone: phone link \n \nMorecomments. \n\n**Attachments:**\n\n\n\n**Jira Ticket:** MyJiraURL", "idList": "MyListID", "idMembers": "member1,member2", "idCardSource": "MySourceCard", "keepFromSource": "checklists" }

I've tried using the .asJsonString function to help with escaping the double quotes, but with no luck. JSON formatters I've tried point to this as the potential issue: `{{issue.description.replace("\n"," \\n")}}'

 

Any ideas?

1 answer

1 accepted

2 votes
Answer accepted
Drew Nedderman
Contributor
July 10, 2024

Looks like I was able to resolve this by using the jsonEncode() function. I changed the body to use that function with the {{issue.summary}} smart values.

{
"name": "{{issue.summary.jsonEncode}}",
"desc": "**Name:** {{issue.summary.jsonEncode}}\n\n**Job Title:** {{issue.Job title}}\n\n**Team:** {{issue.New team}}\n\n**Manager**: {{issue.Manager.displayName}}\n\n**Role Type**: {{issue.Employment type}}\n\n**Start Date**: {{issue.Start date.fullDate}}\n\n**Desired Office Location:** {{issue.Employee location}}\n\n**Machine Type:** {{issue.Machine Type}}\n\n**Tech Needs:** {{issue.Tech Needs}}\n\n**Additional Comments:** {{issue.description.replace("\n"," \\n")}}\n\n**Attachments:**\n\n{{#triggerIssue.attachment}}\n\n* {{filename}}: {{content}}{{/}}\n\n**Jira Ticket:** {{triggerIssue.url}}",
"idList": "650c55b9b4f9b73d31ec0748",
"idMembers": "60f8481fc43352750e5d35bc,57fbafefad9335e482ccb4d9",
"idCardSource": "650c55c82e5ac2e0d4bafeaf",
"keepFromSource": "checklists"
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events