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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

523 views 3 11
Read article

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