It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

[Stactic type checking] - The variable [issue] is undeclared.

We are getting below error. can someone please help me on thisErrors.png

1 answer

1 accepted

1 vote
Answer accepted

Where do you type the script? The issue variable is only available for post functions, validators, conditions. It is not available in Script Console, Listeners, behaviours.

We are declaring in Script Listener and if we are not able to  find out issueTypename .


Below is the my code.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult;
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import groovy.json.*;
import com.atlassian.jira.issue.Issue;

def MutableIssue issueObject = (MutableIssue) issue
def MutableIssue parentIssue = issueObject.getParentObject() as MutableIssue

/* Set debugging level */

/* Initialize global objects */
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueTypeName =

log.debug("LISTENER CPI Wiki Markup==> STARTED")

if (issueTypeName == "Payment Inquiry" || issueTypeName == "Operational Inquiry" || issueTypeName == "Policy Inquiry" ) {
/* Retrieve Comment data */

//def actualComments = ComponentAccessor.getCommentManager().getComments(issueObject)
def actualComments = ComponentAccessor.getCommentManager().getLastComment(issueObject)

log.debug("Process each comment")
actualComments.each {
//def FromEmail = it.getUpdateAuthorFullName()
def FromEmail = actualComments.getAuthorApplicationUser().getEmailAddress()

log.debug("****** getAuthorApplicationUser FromEmail "+ FromEmail)

if(FromEmail != "")
def FromEmail1 = actualComments.getUpdateAuthorFullName()
//def FromEmail = it.getAuthorApplicationUser().getEmailAddress()

log.debug("****** getAuthorApplicationUser "+actualComments.getAuthorApplicationUser())

// FromEmail = it.getAuthorApplicationUser().toString()

log.debug("****** getAuthorApplicationUser FromEmail "+ FromEmail1)
// log.debug ("FromEmail.value: " + FromEmail.value)

def InternalCommunications = customFieldManager.getCustomFieldObjects(issueObject).find { == "Internal Communications"}
def AllCommunication = customFieldManager.getCustomFieldObjects(issueObject).find { == "AllCommunication"}
IssueChangeHolder localFieldChangeHolder = new DefaultIssueChangeHolder()

def newStr = "\n From:" + FromEmail1 + "\n Date and Time:" + actualComments.getCreated() + "\n" +" Body: " + actualComments.getBody() +"\n-----------------------------------------------------------------------------------------------------\n"

log.debug ("newStr: " + newStr)
def newStr1 = newStr
def newStr2 = newStr
def InternalCommunicationOldValue = issueObject.getCustomFieldValue(InternalCommunications)
def ii =InternalCommunicationOldValue.toString()
def OICV = newStr1.toString()
log.debug("New Internal Comments" + OICV)

if(InternalCommunicationOldValue && !ii.contains(OICV))
newStr1 = newStr.toString()+InternalCommunicationOldValue
InternalCommunications.updateValue(null, issueObject, new ModifiedValue(issueObject.getCustomFieldValue(InternalCommunications), newStr1), localFieldChangeHolder)

log.debug("InternalCommunicationOldValue" + InternalCommunicationOldValue)
if (InternalCommunicationOldValue == null)
InternalCommunications.updateValue(null, issueObject, new ModifiedValue(issueObject.getCustomFieldValue(InternalCommunications), OICV), localFieldChangeHolder)
// InternalCommunications.setForeground(Color.white)
log.debug("COMPLETED Updating Internal Communication field")

def AllCommunicationOldValue = issueObject.getCustomFieldValue(AllCommunication)
def ac =InternalCommunicationOldValue.toString()
def OACV = newStr2.toString()

if(AllCommunicationOldValue && !ac.contains(OACV))
newStr2 = newStr.toString()+AllCommunicationOldValue
AllCommunication.updateValue(null, issueObject, new ModifiedValue(issueObject.getCustomFieldValue(AllCommunication), newStr2), localFieldChangeHolder)
log.debug("AllCommunicationOldValue" + AllCommunicationOldValue)
if(AllCommunicationOldValue== null)
AllCommunication.updateValue(null, issueObject, new ModifiedValue(issueObject.getCustomFieldValue(AllCommunication), OACV), localFieldChangeHolder)
log.debug("COMPLETED Updating AllCommunication field")

log.debug("Completed processing all comments")


log.debug("LISTENER CPI Wiki Markup==> COMPLETED for " + issueTypeName)

/* Re-set debugging level */

If you write a listener then you should change issue to event.issue

Now I am getting below error.


where do you type the script? Could you include other parts of your screen to the screenshot?

Thank you very much, now I am not able to see errors after updating event.issue but I ma seeing below warning message 

I am updating script under script Listeners screen.


It will work anyway. It is just a warning about deprecated API. 

Try to change to

Thank you.


What about ?

I do not think you need it at all. You can remove it.

@Alexey Matveev [cPrime] 

So that solved the problem with an event listener ... you get the context from event.issue.

But what about a post function?  Where "issue" is in context, when it running, but not in context from the IDE perspective:

So a line like this:

def cfThisFieldValue = issue.getCustomFieldValue(cfThisField)

Issue has a warning.

How do you fix that? 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

303 views 1 3
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