Hello!
Im currently doing a project to replace an email inbox using the scriptrunner send custom email function.
i require to copy a comment value from a specific user e.g customer.care to a customfield where i will use this customfield value to email out as a thread with an email body.
any suggestions on how to do this?
Many thanks,
Pon
Hi Pon,
Is there a specific reason you want to copy it in a custom field first ? I mean you can extract the comments of a specific user for an issue at the moment you will call the listener/post function.
So an example (and for the latest SR version) of a listener that sends email with body all the comments of a specific user for an issue would be.
Condition and Configuration field
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue // in a post function would be just - issue def commentManager = ComponentAccessor.getCommentManager() //this will be a List of comments made by user with key 'admin' def commentsFromAdmin = commentManager.getComments(issue).findAll {it.getAuthorApplicationUser().key == "admin"} def commentsString = "No comments made from user" if (commentsFromAdmin) { def mostRecentCommentFromAdmin = commentsFromAdmin.last() commentsString = "Comment body: ${mostRecentCommentFromAdmin.getBody()} <br>" + "By ${mostRecentCommentFromAdmin.authorFullName} <br>" + "Created at ${mostRecentCommentFromAdmin.created} <br>" } config.put ("commentsFromUser" , commentsString) return true
Email Body
${commentsFromUser}
please let me know if you need further assistance.
regards, Thanos
Hi Thanos,
Thank you for your reply!
Sorry im abit new to this, so am i suppose to put the above code in postfunction before i call to send custom email and place "${commentsFromUser}" in?
I currently have the following code in postfunction send customer email which works fine, but i need it to send from a specific user called "customer.care":
<% out << cfValues['Email Body - Full'] %> This communication may contain privileged or other confidential information. If you are not the intended recipient, or believe that you have received this communication in error, please do not print, copy, retransmit, disseminate, or otherwise use the information. Also, please indicate to the sender that you have received this email in error, and delete the copy you received. <% if (mostRecentComment != null) out << "-----Response Message-----" << "\n" << "\n" << mostRecentComment %>
Any help would be much appreciated.
Cheers,
Pon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pon,
Updated the script above, in order to return to you the last comment of a specific user. So if it is for a post function then your send custom email configuration will look like
send-last-comment.png
PS. This is for a JIRA v7.*
regards, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thanos,
Thank you so much for your reply.
Not sure if i have a older version but i assume it work, i put in the following code into post function and received the following error: "Property "
Here is the code i put in:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue // in a post function would be just - issue Issue issue def commentManager = ComponentAccessor.getCommentManager() def auser = ComponentAccessor.getUserManager().getUserByKey("customer.care") def commentsFromAdmin = commentManager.getComments(issue).findAll {it.getAuthorApplicationUser().key == "customer.care"} def mostRecentCommentFromAdmin = commentsFromAdmin?.last() def commentsString = "Comment body: ${mostRecentCommentFromAdmin.getBody()} <br>" + "By ${mostRecentCommentFromAdmin.authorFullName} <br>" + "Created at ${mostRecentCommentFromAdmin.created} <br>" config.put ("commentsFromUser" , commentsString) return true
send.JPG
I just have a question about the getUserByKey is this an email address or the string name of comment user.
Many many thanks for your help.
Regards,
Pon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hmm you have an older version... Could you please let me know which , so I can adjust the script ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thanos,
Appreciate your prompt reply.
I have scriptrunner version 3.0.5.
Many thanks,
Pon
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.