Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Cloud Scriptrunner Post Function Notifies (sends email) but inserts brackets in message string

Wayne June 22, 2021

I have a post function that extracts the components and finds email addresses to send from a list. However even when converting the found components and emails to string using <string>.join(", ") it inserts brackets in the email.

In Script Console the email contains what I expect:

Test notification referencing : service1, service2; email john.doe@company.com, joti.bath@company.com

However when attached as a post function the same code gives an email containing:

Test notification referencing : [{service1, {service2; email

- with extra brackets and no email addresses

I'm new to groovy so the code could be better. The post function is of the form:

def myField = issue.fields.find { it.key == "components" }
def value = myField.getValue()
String s = value // Have to assign the value to s to make value a String

def toks = s.tokenize(', ')
def componentsFound = []

toks.eachWithIndex{it, i -> if(it.contains("name=")){componentsFound.add(toks[i].replaceAll("name=",""))}}

def components = ['service1':'john.doe@company.com', 'service2':'joti.bath@domino-uk.com']

def owners = []
components.each{ k, v -> if(componentsFound.contains(k)) {owners.add(v)}}

String componentList = componentsFound.join(", ")
String ownerList = owners.join(", ")

String message = "Test notification referencing : "+componentList+"; email "+ownerList

def resp = post("/rest/api/3/issue/${issue.key}/notify")
.header("Content-Type", "application/json")
.body([
subject: 'Component Bug Notification',
textBody: message,
htmlBody: message,
to: [
watchers: true,
users: [[
name: '<email@company.com>'
]]
]
])
.asString()

1 answer

0 votes
Wayne June 29, 2021

Is there anyone from Atlassian or Adaptavist able to help with the above?

Suggest an answer

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

Atlassian Community Events