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> <---- 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);
}
}
Hi @Anthony Halford,
What about using def in groovy ?
def reporter = issue.getReporter();
or
import com.atlassian.jira.user.ApplicationUser;
ApplicationUser reporter = issue.getReporter();
Using ApplicationUser Reporter looks like it works, but I will need to test it.
Thanks for the swift response @Tansu Akdeniz!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.