Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

ScriptRunner set fixVersion in transition post fuction not working Edited

Hello,

I have been attempting to automatically set the fixVersion of a ticket during a transition post function. So that when someone progresses the ticket its set automatically to latest unreleased version.

I have attempted all the suggestions I found googling (largely from this community) but failed.

I scrambled together all the snippets and with some digging in the API docs i managed to get it to a state where it runs successfully but doesnt apply the change. If anyone can help me figure out what I am doing wrong?

Self hosted Jira server 7.13.5

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import org.apache.log4j.Logger
import org.apache.log4j.Level

def versionManager = ComponentAccessor.getVersionManager()
def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectObjByKey(issue.projectObject.key)
def id = issue.getProjectId()
def uversions = versionManager.getVersionsUnreleased(id, false).collect()


def log = Logger.getLogger("UpdateFixVersion")
log.setLevel(Level.DEBUG)

log.info uversions

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

issue.setFixVersions(uversions)

 

The above produces a successful run after testing it with a ticket but it doesnt update the fix version.

Prints the correct version in the logs:

2020-01-30 16:37:30,151 INFO [UpdateFixVersion]: [COSM-20-05]

Ive tried setting the issue.setFixVersions(uversions) above and below the updateIssue function with the same result

 

UPDATE: Correct answer was supplied by @Leo in the last few comments. The problem was related to the order in which the post functions were arranged

2 answers

1 accepted

0 votes
Answer accepted
Leo Community Leader Jan 31, 2020

Hi @Arthur Francis,

Below script may work for you, I tested it out in my workflow

import com.atlassian.jira.component.ComponentAccessor

def versionManager = ComponentAccessor.getVersionManager()
def project = issue.getProjectObject()
def version = versionManager.getVersionsUnreleased(project.getId(), true)

if (version) {
issue.setFixVersions(version)
log.info("${issue.key} - fix version/s has been updated with ${version}")
}
else{
log.warn("Version does not available")
}

 

Note: if there are more than one unreleased versions all will be updated to current issue

 

BR,

Leo 

Hi @Leo 

Thanks for the quick response, this did not work for me, in fact it did not even print the log line which is strange.

Time (on server): Fri Jan 31 2020 10:49:35 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.

i also tried to create the logger object but that didnt help

Leo Community Leader Jan 31, 2020

It's strange, this is working fine for me. FYI, my scriptrunner version is 5.6.10

Do you see any warnings/error with this script?

ScriptRunner version 5.6.11

 

I dont get any warnings with the syntax and all runs were successful

 

Selection_999(851).pngSelection_999(852).png

Leo Community Leader Jan 31, 2020

try log.warn in if block instead of log.info

it's bit of strange for me :(

Increasing the log level worked for the output

Time (on server): Fri Jan 31 2020 11:27:15 GMT+0100 (Central European Standard Time)

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

2020-01-31 10:27:15,357 WARN [workflow.AbstractScriptWorkflowFunction]: COSM-18110 - fix version/s has been updated with [COSM-20-05]

Says the ticket is updated

Selection_999(853).png

But fixversion still says None. I have tried refreshing and editing the ticket to confirm

Payload 
{ "full.module.key": "com.onresolve.jira.groovy.groovyrunnerrungroovy-function (java.lang.String)", "canned-script": "com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction (java.lang.String)", "disabled": "false (java.lang.String)", "class.name": "com.onresolve.jira.groovy.GroovyFunctionPlugin (java.lang.String)", "issue": "COSM-18110 (com.atlassian.jira.issue.IssueImpl)", "passesCondition": "true (java.lang.Boolean)", "transientVars": { "changeGroup": "[GenericEntity:ChangeGroup][issue,359570][author,afrancis][created,2020-01-31 10:27:15.288][id,3095431] (org.ofbiz.core.entity.GenericValue)", "issue": "COSM-18110 (com.atlassian.jira.issue.IssueImpl)", "configuration": "com.opensymphony.workflow.config.DefaultConfiguration@77a8b06c", "proj": "Project: COSM (com.atlassian.jira.project.ProjectImpl)", "project": "[GenericEntity:Project][name,Cloud Operations Service Management][assigneetype,3][description,This project is for incidents and service requests to be handled by Cloud Operations][projecttype,software][id,14758][counter,18044][avatar,12341][originalkey,FCS][url,https://private.url/display/FCO][lead,afrancis][key,COSM] (org.ofbiz.core.entity.GenericValue)", "currentSteps": "[SimpleStep@2[owner=, actionId=21, status=null]] (java.util.ArrayList)", "store": "com.opensymphony.workflow.spi.ofbiz.OfbizWorkflowStore@2c1124b6", "descriptor": "com.atlassian.jira.workflow.ImmutableWorkflowDescriptor@389689f9", "userKey": "afrancis (java.lang.String)", "originalAssigneeId": "afrancis (java.lang.String)", "entry": "com.opensymphony.workflow.spi.SimpleWorkflowEntry@358d650a", "oldStatus": "IssueConstantImpl[[GenericEntity:Status][sequence,44][statuscategory,2][name,Backlog][iconurl,/images/icons/subtask.gif][description,][id,10037]] (com.atlassian.jira.issue.status.StatusImpl)", "context": "com.opensymphony.workflow.basic.BasicWorkflowContext@6ecc90db", "createdStep": "SimpleStep@3[owner=, actionId=0, status=null] (com.opensymphony.workflow.spi.SimpleStep)", "originalissueobject": "COSM-18110 (com.atlassian.jira.issue.IssueImpl)", "actionId": "21 (java.lang.Integer)", "pkey": "COSM (java.lang.String)", "changeItems": "[com.atlassian.jira.issue.history.ChangeItemBean@57f5d629[fieldType=jira,field=status,from=10037,fromString=Backlog,to=3,toString=In Progress,created=<null>]] (java.util.LinkedList)", "transaction": "com.atlassian.jira.transaction.TransactionSupportImpl$TransactionImpl@5ba0546f" }, "log": "org.apache.log4j.Logger@10d0294a" }
Leo Community Leader Jan 31, 2020

I think , I got your issue. 

What is your post-function order?

Place this post-function on top of everything(I usually do that based on the priority) if not at least on top of generate change history function & re-index post-functions

mostly this would solve your issue

Thanks @Leo ! this worked for me i moved the update the top of the post-function order

Like Leo likes this

Hi @Arthur Francis 

Try move this line:

issue.setFixVersions(uversions)

before this line:

ComponentAccessor.getIssueManager().updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED, false)

See if that works for you.

Kind regards
Jorden 

Thanks for the suggestion @Jorden Van Bogaert  I already tried this approach and it didnt work, @Leo 's suggestion to move the post function order worked for me

Like Jorden Van Bogaert likes this

Suggest an answer

Log in or Sign up to answer
TAGS

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