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

How to set a custom field value with Script Runner on Create using other custom field valu Edited

My apologies if I'm not posting in the correct place.

I have an inline Script Runner post function that works perfectly on a subsequent transition, but does not work on the create transition.

It takes the value from a custom field (Support Queue) and uses that to generate the user group to select from a single select list.

import com.atlassian.jira.component.ComponentAccessor
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()

def queueCf = customFieldManager.getCustomFieldObjectByName("Support Queue")
String qname = issue.getCustomFieldValue(queueCf) 


def singleGroupCf = customFieldManager.getCustomFieldObjectByName("Notify Group")

def group = groupManager.getGroup("Notify " + qname)

issue.setCustomFieldValue(singleGroupCf, [group])

It is working correctly on my "Escalate" transition, but not working on the create transition.  On Create, nothing is populated in the "Notify Group" field.

I am thinking maybe something is not available on create that is available in later transitions?

On create, I actually copy the issue type name into the "Support Queue" field, This is done in a post function prior to the script post function.

If need to use "Issue Type" instead of the custom field to find the name, that would be good too.  

I tried 

String qname = issue.issueType.name

But that didn't work either.  

Any help would be greatly apprciated!

2 answers

I do more or less the same things. Two remarks:

(1) is your Post Function placed before the "Creates the issue originally" function ?

(2) I use (I think you should, but I do not understand why it works in your "Escalate" transition) a MutableIssue  type to update the contents of issues:

import com.atlassian.jira.issue.MutableIssue
...
MutableIssue mutableIssue = issue
mutableIssue.setCustomFieldValue (singleGroupCf, [ group ])

Give this a try ?

 

I updated both transitions (create and escalate) 

It still works on the Escalate transition, but not on the create transition.

Here's the list of post functions on each:

CreatePostFunctions.pngEscalatePostFunctions.png

 

I have tried moving my post function to just about every position, and could not get my custom field to to take the value.

I did think of a different approach that worked though. I created a scripted field that takes the value from "issuetype" and puts "Notify " in front of it.

Then, added a post function to copy the value of one field to another. Copy My scripted field into "Notify Group", and it works like a charm.

Thanks for the help - it's great to have some input from other when you are totally stuck!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

What's New in Confluence Cloud – November 2019 Edition

Hey community! This month we’re excited to share brand new features to help you make your mark on Confluence. If you haven’t already, check out our updates from October and September too! Expre...

40,233 views 44 67
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