import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def commentManager = ComponentAccessor.getCommentManager()
import com.atlassian.jira.issue.MutableIssue
def issue = issue as MutableIssue
def issueType = "Activity"
if (issue.issueType.name == issueType) {
def issueLinkManager = ComponentAccessor.issueLinkManager
def RelevantIssue = issue
issueLinkManager.getOutwardLinks(issue.id).each { issueLink ->
def linkedIssue = issueLink.destinationObject
def commentBody = """${RelevantIssue.key} has been updated:
{quote}
${RelevantIssue.summary}
{quote}
"""
commentManager.create(issueManager.getIssueObject(issue.id), user, commentBody, true)
}
}
Kindly suggest how to fix this error .
You're creating the "issue" variable as a completely empty mutableissue, so there's nothing for the code to work with later in the process.
I can't quite see what you're trying to do with this script because of that. I can see that you want to create a link when the issue type is a certain value, but we don't know where your code is running (console, post function, listener, etc), and there's no issue in the script to ask the issue type of.
Hi Nic,
Thanks a lot for your quick response.
I am very new to scripting in scriptrunner. Whenever a issue is updated a comment needs to be insereted in all its linked issues. Which will lead to send the Notification automatically for linked issues. I found a script in library. This error I am getting if I try to run the script provided in library in console. Below is the script.I am currently trying to run it in console. the error is coming also in Listner. Kindly suggest where shall the script executed, console or listener?
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
// text field containing tiny url *name*
def textFieldName = "Tiny URL"
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def commentManager = ComponentAccessor.getCommentManager()
def resolvedIssue = issue
def cf = customFieldManager.getCustomFieldObjectByName(textFieldName)
def tinyUrl = resolvedIssue.getCustomFieldValue(cf)
// update this query with the project(s) you want to search for the matching url
def query = jqlQueryParser.parseQuery("issueFunction in issueFieldExactMatch('project in (JRTWO)', '$textFieldName', '$tinyUrl')")
def searchResults = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
searchResults.issues.each { issue ->
def commentBody = """${resolvedIssue.key} has been resolved:
{quote}
${resolvedIssue.summary}
{quote}
"""
commentManager.create(issueManager.getIssueObject(issue.id), user, commentBody, true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
// text field containing tiny url *name*
def textFieldName = "Tiny URL"
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def commentManager = ComponentAccessor.getCommentManager()
def resolvedIssue = issue
def cf = customFieldManager.getCustomFieldObjectByName(textFieldName)
def tinyUrl = resolvedIssue.getCustomFieldValue(cf)
// update this query with the project(s) you want to search for the matching url
def query = jqlQueryParser.parseQuery("issueFunction in issueFieldExactMatch('project in (JRTWO)', '$textFieldName', '$tinyUrl')")
def searchResults = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
searchResults.issues.each { issue ->
def commentBody = """${resolvedIssue.key} has been resolved:
{quote}
${resolvedIssue.summary}
{quote}
"""
commentManager.create(issueManager.getIssueObject(issue.id), user, commentBody, true)
}
above script create a comment automatically on all linked issues whenever an issue is resolved
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So that's not the same script you posted before, and it also has some errors in it (note the most of it is commented out!). But I think that you need the explanation of why the first one and this one might be doing.
I think you've copied a script which is a post-function. These run as issues go through transitions, and they have the context of that issue available to them automatically.
When you ran that in a console, it failed, because there is no issue context. I guess you tried to fix that by creating an issue object on-the-fly, but you didn't actually give it anything that was an issue, so it continued to fail.
The latest script should work (once the comment is fixed), but only as a post-function - it does try to define the "issue" object, it takes the "current issue that the post-function is running against"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nic,
I had put below code in Email Template of Post funtion .
def User = com.atlassian.jira.component.ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def issueLinkManager = com.atlassian.jira.component.ComponentAccessor.getIssueLinkManager() def linkCollection = issueLinkManager?.getLinkCollection(issue, User) //collect all issues in a list def allLinkedIssues = linkCollection?.getAllIssues() //concat all issues links in a string def linkedIssues = "<br>" for (def issue in allLinkedIssues) { linkedIssues = linkedIssues + '<a href="tracker.redbrickhealth.local/jira/browse/' + issue.key + '">' + issue.key + '</a><br>' }
The execution was succesfull, but No email was sent, I got following Log information:
"2019-03-13 12:08:29,289 WARN [postfunctions.SendCustomEmail]: No mail server or sending disabled."
Could you please suggest How can the email be sent?
Best Regards,
jyotsna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to configure an outgoing email server (or service) to send the email. The email template function relies on your globally set email server.
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.