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

Update Customfield listened using "ScriptRunner for JIRA"

Hello,

 

I created a script for update priority using Urgency and Impact. This script works as post function but when I'm using as listened is doing nothing. Any error appears in the code but the priority is not updated automatically.

Could you help me?

 

 

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 = event.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)


if (validationResult.isValid()) {
issueService.update(user, validationResult)
} else {
log.warn validationResult.errorCollection.errors
}

1 answer

1 accepted

1 vote
Answer accepted
Antoine Berry Community Leader Nov 25, 2019

Hi @Juan José Marchal Gómez ,

It should work in a listener if it works in a postfunction. Are you sure you mapped your script to the correct event so that it is triggered ? In that case try to add logs in your script to track any error and display the values of your variables.

Antoine

Hello @Antoine Berry 

thanks for the answer.

The issue has been runned 15 times since this configuration. The "triggered" of listener is issue updated.

Here you are the outcome.

of course No failures in the last 15 executions()

Custom listener
Projects: IESD
Events: Issue Updated
No note

LOGS:

Time (on server): Mon Nov 25 2019 13:36:24 GMT+0100 (Central European Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

No logs were found for this execution.

PAYLOAD:

{
    "projects": "[IESD] (java.util.ArrayList)",
    "issue": "IESD-13820 (com.atlassian.jira.issue.IssueImpl)",
    "log": "org.apache.log4j.Logger@10161a7d",
    "friendlyEventNames": "Issue Updated (java.lang.String)",
    "version": "3 (java.lang.Integer)",
    "name": "Custom listener (java.lang.String)",
    "canned-script": "com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener (java.lang.String)",
    "id": "e608a472-ba24-4a06-93a1-2dbc956c28ea (java.lang.String)",
    "$beanContext": "com.onresolve.scriptrunner.beans.ScriptRunnerBackedBeanContext@5e714407",
    "event": "com.atlassian.jira.event.issue.IssueEvent@351ce617[issue=IESD-13820,comment=<null>,worklog=<null>,changelog=[GenericEntity:ChangeGroup][issue,32279][author,nacosta][created,2019-11-25 14:10:35.322][id,179504],eventTypeId=2,sendMail=false,params={eventsource=action, baseurl=https://helpdesk.emdep.com},subtasksUpdated=true,spanningOperation=Optional.empty]",
    "bundle": "com.atlassian.jira.event.issue.DefaultIssueEventBundle@35279e3a",
    "events": "[2] (java.util.ArrayList)"
}

 

Thanks in advance.

Antoine Berry Community Leader Nov 25, 2019

What I meant is to add loggers lines in your script, such as :

issue.setPriorityId(priority.id)

log.error("issueInputParameters : " + issueInputParameters)
def validationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)
log.error("validationResult : " + validationResult)

if (validationResult.isValid()) {
issueService.update(user, validationResult)
log.error("issue updated")
} else {
log.warn validationResult.errorCollection.errors
}

to try and check what is wrong.

Hello @Antoine Berry 

Thanks for show me how to log information. I didn't know this option. I'm beginner in scriptRunner still.

The outcome is:

 

Time (on server): Mon Nov 25 2019 15:13:21 GMT+0100 (Central European Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2019-11-25 15:13:21,258 ERROR [runner.AbstractScriptRunner]: issueInputParameters : com.atlassian.jira.issue.IssueInputParametersImpl@2594a4a1
2019-11-25 15:13:21,258 ERROR [runner.AbstractScriptRunner]: validationResult : com.atlassian.jira.bc.issue.IssueService$UpdateValidationResult@4f5024ac

Working....

The only different is your recommendations of logging.

I don't understand but works...

Thanks a lot.

Like Antoine Berry likes this
Antoine Berry Community Leader Nov 25, 2019

Glad it worked out. I have been having a few strange cases where adding a log also solved the issue, and I still do not know why.

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...

52 views 0 2
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