I know JIRA has API method for share issue by email. And I have custom script in post-function. I want to send this email from my script. Built-in script Send Custom Email doesn't fit for me because I need send email just like if I pressed Share button on Issue screen. API doesn't fit too.
I dont know other ways for it.
What's wrong with the Send Custom Email? It's not clear why it's not sufficient.
Code example
First of all, the Share feature is provided by a plugin, so we need to use the @WithPlugin and @PluginModule annotations instead of just importing the classes.
Second, we must construct a ShareBean, which represents most of the input for the operation. Then, we need to pass the bean, the Issue, and the Sender (user) to ShareService.validateShareIssue() method.
Finally, this returns a Validation Result. The result is either Valid or has Errors. We check the state and either log an error, or proceed and share the issue.
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.plugins.share.ShareService
import com.atlassian.jira.plugins.share.ShareBean
import java.util.Collections
log.setLevel(org.apache.log4j.Level.INFO)
@WithPlugin("com.atlassian.jira.jira-share-plugin")
@PluginModule
ShareService shareService
def remoteUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def user = ComponentAccessor.userManager.getUserByKey("admin")
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("PROJ-1")
def userkeys = Collections.singleton(user.key) as Set<String>
def emails = Collections.emptySet() as Set<String>
def message = "Hello World!" as String
def shareBean = new ShareBean(
userkeys,
emails,
message,
null // jql
)
def result = shareService.validateShareIssue(remoteUser, shareBean, issue)
if(!result.isValid()) {
log.error "Failed to validate Share Issue parameters:\n${result.errorCollection}"
return null
}
log.info "${remoteUser.displayName} is sharing ${issue.key} ${issue.summary} with ${user.displayName}."
shareService.shareIssue(result)
Because I need exactely same email as if I pressed Share buttom. Email must be autogenerated by JIRA and must have appropriate styles. Just like in the picture:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then just construct your own template that looks like it. You can copy it from the emails you get.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So.. There is no way to do it with standard JIRA tools?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Very few people have tried to do what you're doing.
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.
Oh excellent! :) I hadn't ever seen those classes or API before, so I wasn't really sure... I did a single test and didn't see it work... I guess I'll have to look closer!
Glad it worked though, and thanks for the update!
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.
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.