Building a email via custom script post function

Anthony Halford July 9, 2018

Hi,

I am trying to build a custom script post function, to send off a feedback form using the reporter as the email recipient. I get stuck at the following line:

User reporter = issue.getReporterUser()

Cannot assign value of type com.atlassian.jira.user.ApplicationUser to variable of type com.atlassian.crowd.ambedded.api.User

Please could you tell me what the correct variable is to use for the reporterUser?

Please see script below for an idea of what the intended email should look like.


import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.mail.MailException
import com.atlassian.mail.queue.MailQueueItem
import com.atlassian.mail.queue.SingleMailQueueItem
import com.atlassian.jira.mail.Email
import com.atlassian.jira.config.properties.ApplicationProperties
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.WorkflowException
ComponentManager componentManager = ComponentManager.getInstance()
GroupManager groupManager = ComponentAccessor.getGroupManager();
ApplicationProperties applicationProperties = ComponentAccessor.getApplicationProperties()
String baseUrl = applicationProperties.getString(APKeys.JIRA_BASEURL)
Issue issue = issue;
User reporter = issue.getReporterUser()
Group itgroup = groupManager.getGroup("IT Services")
if (!groupManager.getUserNamesInGroup(itgroup).contains(reporter.getName()))
{
Email email = new Email(reporter.emailAddress);
email.setSubject("JIRA " + issue.key+" has been closed, How did it go?");
email.setFrom("jira@just-eat.com");
email.setMimeType("text/html");
StringBuilder sb = new StringBuilder();
sb.append("<b>Hi "+reporter.getDisplayName().split(" ")[0]+",</b><br><br>");
sb.append("Please help us get better by telling us what you think about our service and how we dealt with your JIRA.<br><br>")
sb.append("<a href=\"Feedback Form URL inserted here">")
sb.append("It will only take a minute...");
sb.append("</a>&nbsp; <---- Click here for survey<br><br>");
sb.append("We'd really appreciate it as the feedback will feed into our performance and development plans.<br><br>Thank you from<br><b>End-User Computing</b>");
email.setBody(sb.toString());
MailQueueItem singleMailQueueItem = new SingleMailQueueItem(email);
try
{
singleMailQueueItem.send();
}
catch (MailException e)
{
throw new WorkflowException("Failed to send Feedback Email due to: " + e.getMessage(), e);
}
}

2 answers

1 accepted

0 votes
Answer accepted
Tansu Akdeniz
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 9, 2018

Hi @Anthony Halford,

What about using def in groovy ?

def reporter = issue.getReporter();

 or 

import com.atlassian.jira.user.ApplicationUser;
ApplicationUser reporter = issue.getReporter();
Anthony Halford July 9, 2018

Using ApplicationUser Reporter looks like it works, but I will need to test it.

Thanks for the swift response @Tansu Akdeniz!

Tansu Akdeniz
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 9, 2018

You are welcome @Anthony Halford

Anthony Halford July 9, 2018

Hi @Tansu Akdeniz

Any ideas as to why I am getting this error message? Seems pretty pointless :(

Capture 2.PNG

0 votes
Tansu Akdeniz
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 9, 2018

@Anthony Halford In JIRA_HOME directory, there is a default Scripts folder. It is better to put your groovy codes into this. Then just write the file name in UI as "pf-feedback.groovy". It takes the root as /Scripts directory. Btw there could be some warnings but it doesnt prevent your code unless an error.

Suggest an answer

Log in or Sign up to answer