Forums

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

Groovy Post function on Create transition can’t set custom field

Deleted user September 18, 2020

Hello,

We have recently upgraded to JIRA v 8.11.0

Our aim is to create a new Workflow which will create a new JIRA and set the Values of some Custom Fields.

The Workflow does:

  • Creates the issue
  • Re-index an issue to keep indexes in sync with the database.
  • Fire a Issue Created event that can be processed by the listeners.
  • Run the groovy script below

However, the existing Custom Fields are not getting updated

Can someone give me a hint why I am not able to set the values of Custom Fields of newly created Issues even if the custom script runs after the issue is created ?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import org.apache.log4j.Category

// ComponentManager has been deprecated since JIRA 7.11
// https://community.atlassian.com/t5/Answers-Developer-Questions/Groovy-Post-function-on-Create-transition-can-t-set-custom-field/qaq-p/474592

log = Category.getInstance(“com.onresolve.jira.groovy”)
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug “start debugging ASS-1482”

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder()
Issue issue = issue

def allCustomfields = customFieldManager.getCustomFieldObjects(issue)
def count = 0
def i=0
for(i=0;i<allCustomfields.size();i++){
log.debug “–”+allCustomfields[i].getFieldName()+"–"
}
log.debug “finished display customfields”

def opsKycField = customFieldManager.getCustomFieldObjects(issue).find {it.name == ‘OPS-KYC analyst’}
opsKycField.updateValue(null, issue, new ModifiedValue("", “SB36AU”), changeHolder)
log.debug "PR ID now set to: " +issue.getCustomFieldValue(opsKycField)

Additionally, nothing appears in the log file.


Test of ASS-1482


2020-09-15 11:29:34,249+0200 http-nio-8080-exec-15 INFO SB36AU 689x72783x1 pvctuf /secure/admin/ViewLogging!markLogs.jspa [c.a.j.util.log.LogMarker]


Test of ASS-1482 end

2 answers

0 votes
Gustavo Félix
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.
September 18, 2020

Hi @[deleted] 

opsKycField.updateValue(null, issue, new ModifiedValue("", “SB36AU”), changeHolder)

The "" should be the old value.
you could do this
opsKycField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(opsKycField), “SB36AU”), changeHolder)

Let me know if this works for you.

0 votes
Niranjan
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.
September 18, 2020

Hi @[deleted] ,

Before getting into the script, I am thinking if you may need to reorder the workflow post function. 

 

  • Creates the issue
  • Run the groovy script
  • Re-index an issue to keep indexes in sync with the database.
  • Fire a Issue Created event that can be processed by the listeners.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events