Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

ScriptRunner: Post Function to update component value for given issue


* Working on post function which needs to update value of Issue upon creation


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.Project

import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.CreateSubtask")

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueSecurityLevelManager issueSecMgr = ComponentAccessor.getIssueSecurityLevelManager()

//Set Issue Security level

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField issueAreaField = customFieldManager.getCustomFieldObjectByName("Issue Area");
String componentName = issueAreaField.getValue(issue)

Project project = issue.getProjectObject()
ProjectComponent component = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(), componentName)
if (component){
   log.debug "Component is: " + component




Don't see any errors in log either. Any idea what I'm missing here. 


2 answers

1 accepted

0 votes
Answer accepted

I'm able to solve specific problem using Script Runner Behavior as mentioned below.

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours

def components = getFieldById("components").getValue() as List<ProjectComponent>
if (components.size() > 1){
getFieldById("components").setError("Please select only one component related to your work.")

But still would like to know why post function is not working.

Hi @Raju Kadam @Carmen Creswell [Adaptavist] 


I have this script he dupplicate the components between project and i would like when i change the name for the component , the name in the other project but actually when i change the name he create a new component with name changed


You can help me ??


Thanks in advance


Hi Raju!

There are several possible reasons that the post function isn't working. The way the script is written, if it can't find a component, it will simply skip it. In other words, if your component name doesn't quite match, the script won't throw an error. Try adding an 'else' statement to your code, something like

if (component){
   log.debug "Component is: " + component
} else {
log.debug ("Component not found")

and seeing if you get any logs here! 

You can also check the order of your post function execution. Here is a link to the documentation on the post function execution order. If you could, please include a screenshot of the execution order of the transition that this post function is on.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events