Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,295,600
Community Members
 
Community Events
165
Community Groups

Share board via mail using scriptrunner

Edited

Hi everyone,

I would like to send a mail with a link of the current board.

I'm using scriptrunner but I m not able to find the current id or url...

Can anyone help me?

1 answer

Hi @Tommaso Scorteccia

For your requirement, you can try to trigger the email using the ScriptRunner console with something like this:-

import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.web.rapid.view.RapidViewHelper
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.Email
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import groovy.xml.MarkupBuilder

@WithPlugin("com.pyxis.greenhopper.jira")

@JiraAgileBean
RapidViewService rapidViewService

@JiraAgileBean
RapidViewHelper rapidViewHelper

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def applicationProperties = ComponentAccessor.applicationProperties
def hostUrl = applicationProperties.getString('jira.baseurl')
def views = rapidViewService.getRapidViews(loggedInUser).value
final def projectKey = 'MOCK'

def emailBody = new StringWriter()
def html = new MarkupBuilder(emailBody)

html.html {
body {
views.each {
if (it.name == "${projectKey} board") {
a ( href : "${hostUrl}/secure/RapidBoard.jspa?rapidView=${it.id}&projectKey=${projectKey}") {
mkp.yield "Link to ${projectKey} board"
}
}
}
}
}

final static creatMessage(String to, String subject, String content) {
def mailServerManager = ComponentAccessor.mailServerManager
def mailServer = mailServerManager.defaultSMTPMailServer

def email = new Email(to)
email.setSubject(subject)
email.setMimeType("text/html")
email.setBody(content)

def threadClassLoader = Thread.currentThread().contextClassLoader
Thread.currentThread().contextClassLoader = mailServer.class.classLoader
mailServer.send(email)
Thread.currentThread().contextClassLoader = threadClassLoader
}

creatMessage('user@samplemail.com', 'Board Link', emailBody.toString())

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to modify it accordingly.

Below is a print screen of the email link received:-

email_link.png

Upon clicking the link, the receiver is re-directed to the board. However, you must ensure that the receiver has the required permission to view the board. 

I hope this helps to answer your question. :)

 

Thank you and Kind regards,

Ram

Hi @Ram Kumar Aravindakshan _Adaptavist_ , thank you for the example

I'm trying your script, but my board structure is quite difference, I have a one project with different board inside. For example

Project "Apple"

Boar "Develop Board"

Board "Testing Board" and so on..

I see that to identify the board you use the condition

if (it.name == "${projectKey} board")

but I can't use this condition for my scope 

What i want to do is a button in the board that send a link like window.location.href in javascript, or a function like "getcurrentboard" :)

Thank in advance

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

302 views 0 9
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you