Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

I am getting an error: [static Type Checking]-The variable [issue] is undeclared in below script.

Jyotsna Schmeckenbecher March 11, 2019

 

 

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 .

1 answer

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2019

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.

Jyotsna Schmeckenbecher March 12, 2019

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) }

Jyotsna Schmeckenbecher March 12, 2019 edited
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

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 12, 2019

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"

Jyotsna Schmeckenbecher March 13, 2019

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
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 13, 2019

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.

Jyotsna Schmeckenbecher March 14, 2019

Thank you Nic !

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events