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 votes

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,755 views 11 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot