Forums

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

Script works in postfunction but not as Listener (Script Runner)

GS1337
Contributor
March 18, 2020

Hi,

 

with this script i copy the value of 2 custom fields into the summary and description field of an issue. When i have this script in a workflow transission as post function it works, not when i implement it as a listener tho: 

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

long CF_ID_DESCRIPTION_OF_ISSUE = 21036
long CF_ID_SUMMARY_OF_ISSUE = 21035

CustomFieldManager cfManager = ComponentAccessor.getCustomFieldManager()

CustomField descriptionOfIssueCf = cfManager.getCustomFieldObject(CF_ID_DESCRIPTION_OF_ISSUE)
CustomField summaryofIssueCf = cfManager.getCustomFieldObject(CF_ID_SUMMARY_OF_ISSUE)

String descriptionValue = issue.getDescription()
String summaryValue = issue.getSummary()

issue.setCustomFieldValue(descriptionOfIssueCf, descriptionValue)
issue.setCustomFieldValue(summaryofIssueCf, summaryValue)

 

thx for the help

1 answer

0 votes
Leo
Community Champion
March 24, 2020

Hi @GS1337,

The update method/process is different from post-function, below is my one of sample script which would give you some idea

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue

def changeHolder = new DefaultIssueChangeHolder();
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Field name")
def value = "Some Value"
def myIssue = event.issue

String val = myIssue.getCustomFieldValue(cfSelect)

if(val){
value = value+val
cfSelect.updateValue(null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(cfSelect),value), changeHolder)

 BR,

Leo

Suggest an answer

Log in or Sign up to answer