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

Your Points Tracker
Challenges
Leaderboard
  • 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
Recognition
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?
Kudos
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

How to write a Behavior to auto-populate the Summary of an issue based upon multiple field values

When a user creates or edits an issue, I'd like the summary value of that issue to be auto-populated as the user enters values for 3 fields on the create/edit forms.

The summary value should look like "Pod - Name - Role"

Create issue screen.png

As you can see below, I've written 4 behaviors mapped to this project and issue type.  I don't feel like this is an elegant solution at all and it doesn't work.  I'm hoping someone far better at this than me can point me on the correct path.

My scriptrunner behavior summary code is:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.SUMMARY

@BaseScript FieldBehaviours fieldBehaviours


def summary = getFieldById("summary")
summary.setDescription("Will be set auotmatically when user selects Pod, enters a Name and chooses a Role")

 

My scriptrunner behavior pod code is:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.SUMMARY

@BaseScript FieldBehaviours fieldBehaviours

def pod = getFieldByName("Pod").value
def name = getFieldByName("Name").value
def role = getFieldByName("Role").value

def summary1 = getFieldById("summary")

//summary1.setDescription("Will be set auotmatically when user selects Pod, enters a Name and chooses a Role")
summary1.setFormValue("${pod.} + " - " + ${name} + " - " + ${role}")

 

My scriptrunner behavior name code is:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.SUMMARY

@BaseScript FieldBehaviours fieldBehaviours

def pod2 = getFieldByName("Pod").value
def name2 = getFieldByName("Name").value
def role2 = getFieldByName("Role").value

def summary2 = getFieldById("summary")

//summary2.setDescription("Will be set auotmatically when user selects Pod, enters a Name and chooses a Role")
summary2.setFormValue("${pod2} + " - " + ${name2} + " - " + ${role2}")

 

My scriptrunner behavior role code is:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.SUMMARY

@BaseScript FieldBehaviours fieldBehaviours

def pod3 = getFieldByName("Pod").value
def name3 = getFieldByName("Name").value
def role3 = getFieldByName("Role").value

def summary3 = getFieldById("summary")

//summary3.setDescription("Will be set auotmatically when user selects Pod, enters a Name and chooses a Role")
summary3.setFormValue("${pod3} + " - " + ${name3} + " - " + ${role3}")

 

 

 

1 answer

1 accepted

1 vote
Answer accepted

Since each field update event should trigger a change in the summary, I think the best solution is to store your script in your script root and apply the same script field in each field.

The alternative, is to force users to fill in the fields in a certain order and trigger the update on the last one only. I think that's even less elegant

So what I recommend is:

Initializer:

getFieldById('summary').setReadOnly(true).setDescription("""<span class="greenText">Populated automatically from Pod, Name and Role</span>""")

Now, your Pod field looks like a scriptrunner issue picker field, so I'd recommend the following in a script file (use script editor to create this):

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
@BaseScript FieldBehaviours fieldBehaviours

def pod = getFieldByName("Pod").value ?: 'podTbd'
def name = getFieldByName("Name").value ?: 'nameTbd'
def role = getFieldByName("Role").value ?: 'roleTbd'
def podIssue = ComponentAccessor.issueManager.getIssueObject(pod as String)
def summary = getFieldById("summary")

summary.setFormValue("$podIssue.summary - $name - $role")

Add that script file to each of your fields with the method "run"

This is brilliant Peter!

I knew I was on the right track but you took it over the finish line.  I like how concise your solution is.  I can easily understand what's going on here.

Having this as 1 script file and applying this server-side script is convenient.

I see how you are getting the Pod field (which is a ScriptRunner issue picker field, correct) as a string and then getting the Issue Object from that.  That allows us to then grab the summary of that Pod object..which is the info we want.  Very clever.

I was struggling with this syntax too ("$podIssue.summary - $name - $role") which now I see how it works.  I can call the different variables in just 1 parenthesis.

Like Peter-Dave Sheehan likes this

Suggest an answer

Log in or Sign up to answer
TAGS
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...

299 views 9 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