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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

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
4,552,097
Community Members
 
Community Events
184
Community Groups

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

2 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 10, 2021

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

Atlassian Community Events