Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

[static type checking] The variable [issue] is undeclared

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

// get current issue
def issue = issue as Issue

 

Hello, this is my first scriptRunner script and...this is embarrassing but...I don't find why the variable is undeclared..

 

best regards and thanks in advance.

2 answers

1 accepted

0 votes
Answer accepted
Leonard Chew Community Leader Nov 21, 2019

Get a specific issue on Script Console:

 

import org.apache.log4j.Level
log.setLevel(Level.DEBUG)

import com.atlassian.jira.component.ComponentAccessor

def issueKey = "TEC-123"
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject(issueKey)

log.debug('my issue summary is: ' +issue.summary)

Hello Leonard,

thanks a lot. Works.

But, I'm trying to create a variable matching 2 custom fields of selected issue.

So, what I need is that the "TEC-123" instead of a specific issue, will be a "parameter".

For example, If I'm running this script in a transition, I want that be the issue of the transition.

How I should declare it in my script to give the "issue transitioned"?

Best regards.

Leonard Chew Community Leader Nov 22, 2019

If you are running a postfunction script in a transition, then there is no need to get the "issue" object, as it is already per default set to the issue that is being transitioned.

Create a postfunction script with this code:

log.warn('my transitioned issue is: ' +issue.summary)

When the script gets executed (make sure you transition an issue based on this workflow), you will see that it works without anything else. 

Thanks again Leonard,

what I'm starting to understand is, depend on the place that you are "doing" the script, needs or not some declaration. I will keep care with this.

Can I tell you one last question? only for understanding that I'm in the right way for working with ScriptRunner.

I created the post function and added to the transition. I checked but nothing happens.

The outcomes of this scripts, where I can see?

Because after running, where is saving the information, If I want to see in the screen I should save in a new script custom field?

Best regards.

Leonard Chew Community Leader Nov 22, 2019

A summary of the last 15 executions can be seen if you expand your postfunction.

Everything you log can be seen in the log section.

image.png

See also:

https://scriptrunner.adaptavist.com/latest/jira/tutorials/scripted-post-functions-tutorial.html

Here you are the first script.

This script is runned as postfunction. For begginers, some comments:

 

1) Check it first in console. For doing it you can use the following lines that will be commented when you will save as postfunciton.

//def issueKey = "IESD-11905"
//def issueManager = ComponentAccessor.getIssueManager()
//def issue = issueManager.getIssueObject(issueKey)

2) You can use "return Variable" to check if the script is going well step by step. For example, after the line  

def priorityName = priorityMatrix[urgency.value][impact.value]

 

you can do return priorityName.name and if the information is not null, this is correct.

Best regards.

Thanks in advance to @Leonard Chew

Within him, this first automation wasn't done.

 

__________________________________________________________________________

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.customfields.option.Option


// This is a two dimensional map to represent the matrix
// Keys along left is urgency and second dimension keys is the impact
// This is a two dimensional map to represent the matrix
// Keys along left is urgency and second dimension keys is the impact
def priorityMatrix = [
"Very High - Totally stopped": ["All Plants": "Highest", "More than one plant": "Highest", "Partial or totally production plant / More than one department": "High", "Some users / One department / Individual user": "Medium"],
"High - Stopped": ["All Plants": "Highest", "More than one plant": "Highest", "Partial or totally production plant / More than one department": "High", "Some users / One department / Individual user": "Medium"],
"Medium - Works with major limitation": ["All Plants": "High", "More than one plant": "High", "Partial or totally production plant / More than one department": "Medium", "Some users / One department / Individual user": "Low"],
"Low - Works with limitation": ["All Plants": "Medium", "More than one plant": "Medium", "Partial or totally production plant / More than one department": "Low", "Some users / One department / Individual user": "Low"],
]

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def issue = issue as Issue
//def issueKey = "IESD-11905"
//def issueManager = ComponentAccessor.getIssueManager()
//def issue = issueManager.getIssueObject(issueKey)

def urgencyField = customFieldManager.getCustomFieldObjectsByName("Urgency")

def impactField = customFieldManager.getCustomFieldObjectsByName("Impact")

def urgency = issue.getCustomFieldValue(urgencyField[0]) as Option

def impact = issue.getCustomFieldValue(impactField[0]) as Option

def priorityName = priorityMatrix[urgency.value][impact.value]

def priority = constantsManager.getPriorities().find {it.name == priorityName.toString()}

def issueInputParameters = new IssueInputParametersImpl()

issueInputParameters.setPriorityId(priority.id)
issueInputParameters.setSkipScreenCheck(true)

issue.setPriorityId(priority.id)

def validationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

65 views 0 3
Read article

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