Groovy Post Function email replace value

I trying to produce an groovy email post function where a cfValue is assigned to a string, then remove a portion of the string and then place in the html email. Below is the"Email template" with the "Email format" set to HTML, and the current output.

<html>
<body>
<b>Summary: </b><% out << issue.summary %><br>
<b>Separating user: </b><% out << cfValues['Separating user'] %> = Please ignore the :####<br>
<b>UID of Separated: </b><% out << cfValues['UID of Separated'] %><br>
<b>Reports To: </b><% out << cfValues['Reports To'] %><br>
<b>Manager's UID: </b><% out << cfValues['Manager\'s UID'] %><br>
<b>Work Location: </b><% out << cfValues['Work Location'] %><br>
<b>Other Work Location: </b><% out << cfValues['Other Work Location'] %><br>
<b>Effective Date: </b><% out << cfValues['Date Requested'] %>
</body>
</html>

Summary: Separation of Cubicle Monkey

Separating user: klynch:10000 = Please ignore the :####
UID of Separated: test1234
Reports To: klynch:10000
UID: test4321
Work Location: CA02 (GBR) (611 N Brand Blvd, Glendale, CA 91203)
Other Work Location: NA
Effective Date: 2013-03-29 00:00:00.0

I want the Separating user: and Reports To: output to be (no :10000) at the end

Summary: Separation of Cubicle Monkey

Separating user: klynch
UID of Separated: test1234
Reports To: klynch
UID: test4321
Work Location: CA02 (GBR) (611 N Brand Blvd, Glendale, CA 91203)
Other Work Location: NA
Effective Date: 2013-03-29 00:00:00.0

I've tested string replacement with and the output it correct

<script type="text/javascript">
var str = "klynch:10000";
var n = str.replace(":10000","");
document.write(n);
</script>

output shows klynch without the :10000

I tried adding the following inside the body, but it outputs nothing in return and I'm not seeing anything in the log as to why or any error.

<script type="text/javascript">
var str = cfValues['Separating user'];
document.write(str);
var n = str.replace(":10000","");
document.write(n);
</script>

I'm assuming that the cfValues['Separating user'] does not work inside the script tag. How do I get it so that the cfvalue can be stripped of it's :10000 at the end and then placed in the email correctly.

Thanks

1 answer

1 accepted

0 vote

Javascript is not groovy... so not sure what your JS snippets demonstrate.

Is the "Separating user" field a user custom field? If so you can get the username by just appending .name ie cfValues['Sep User'].name. This would be better than doing string manipulation.

Otherwise you could do cfValues[x].split(":").getAt(0)

but you will get an exception if no value is filled.

wow, thanks Jamie. That was easy :-p

Np. If you used the former you should probably do:

cfValues['Sep User']?.name

This will just return null if the user field is null, without throwing a null pointer exception.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

815 views 2 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you