Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Automate a custom field based on changing the status of an Issue

Hi, I am net to script runner and have only the basic knowledge. 

I am trying to automate an task  where we update an custom field.

The custom field is an radio button with 3 options  None , planned ,Unplanned .

the task is Each time an  story is marked as done and if this story is linked to a RM ticket we should change the type of change field to be planned or unplanned :

conditions :

If issue linked while Status = Scheduled, then “Type of change” field for issue = Planned

If issue linked while Status = Scope Freeze, then “Type of change” field for issue = Unplanned

If issue linked while Status = Code Freeze, then “Type of change” field for issue = Unplanned


1 answer

0 votes

In a postfunction for your workflow transition where the main story is being marked as done, you can add a sriptrunner post function using "custom script post function" with a script somewhat like this:

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.issueLinkManager
def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager

def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def typeOfChangeCf = customFieldManager.getCustomFieldObjectByName('Type of change')
def cfConfig = typeOfChangeCf.getRelevantConfig(issue)
def changeOptions = optionsManager.getOptions(cfConfig)
def plannedOpt = changeOptions.find{it.value == 'Planned'}
def unplannedOpt = changeOptions.find{it.value == 'Unplanned'}

def linkedRMIssues = issueLinkManager.getLinkCollection(issue, currentUser)?.allIssues?.findAll{it.projectObject.key == 'RM'}

if (linkedRMIssues.any{ == 'Scheduled'}) {
issue.setCustomFieldValue(typeOfChangeCf, plannedOpt )
} else if (linkedRMIssues.any{ == 'Scope Freeze'}) {
issue.setCustomFieldValue(typeOfChangeCf, unplannedOpt )
} else if (linkedRMIssues.any{ == 'Code Freeze'}) {
issue.setCustomFieldValue(typeOfChangeCf, unplannedOpt )

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

272 views 8 7
Read article

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