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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


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

0 votes
Carmen Creswell [Adaptavist]
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.
May 15, 2018


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
AUG Leaders

Atlassian Community Events