Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Set Summary and Description based on label and component values

Hi all,

I want to preload a template for my users to follow when creating certain issues. We use an issue type for users to reach out to management for publishing access, and ideally, we'd like to provide a template for them to fill out whenever they select the component "Open Source" and set/select the label "Publish_Blog".

This is what I have so far set as the initialiser for publish access issue types in our project:

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.COMPONENTS
import static com.atlassian.jira.issue.IssueFieldConstants.LABELS

def desc = getFieldById("description")
def summary = getFieldById("summary")

def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def components = projectComponentManager.findAllForProject(issueContext.projectObject.id)

def defaultValue = """1. Where can we find the text you wish to publish? Provide a Google Doc or repo link. See examples at _______.com
2. What meta tags should be added to the post?
3. Who is the author and owning team? Who should this post be attributed to?
4. What is the business value to Avg Jo's for publishing this post?
5. Does your manager and project architect that this should be published, including review for confidential internal information?
6. What is the name of your L2 for approval? Please add to Reviewer field.
7. Should this be distributed on Avg Jo's social channels?
8. Did someone from your group's comms team review and edit the content?
9. Is there an embargo date (don't publish before) or deadline (must publish by)? Please set Due Date to desired publish date""".replaceAll(/ /, '')

def defaultValue2 = """Request to publish public engineering blog post for <project or team name>???""".replaceAll(/ /, '')

if ((getFieldById(LABELS)) == "Publish_Blog" && getFieldById(COMPONENTS) == "Open Source" && getActionName() in ["Create Issue", "Create"]) {
desc.setFormValue(defaultValue)
summary.setFormValue(defaultValue2)
}


This unfortunately doesn’t work because when I navigate to the Create Issue form and set the component and label fields as defined, summary and description are still null.

Any help would be highly appreciated .

2 answers

0 votes

An initialiser in a behaviour only runs when the form is initially loaded.  It does not "react" to values changing in the form.  For that you will need to add fields you want the behaviour to react to (such as labels) and add server side script.

Thanks for the response @Raynard Rhodes .

I updated the script as shown:

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.COMPONENTS
import static com.atlassian.jira.issue.IssueFieldConstants.LABELS

def desc = getFieldById("description")
def summary = getFieldById("summary")

def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def components = projectComponentManager.findAllForProject(issueContext.projectObject.id)

def compVal = getFieldById(COMPONENTS).getValue()
def labelVal = getFieldById(LABELS).getValue()

def defaultValue = """1. Where can we find the text you wish to publish? Provide a Google Doc or repo link. See examples at _______.com
2. What meta tags should be added to the post?
3. Who is the author and owning team? Who should this post be attributed to?
4. What is the business value to Avg Jo's for publishing this post?
5. Does your manager and project architect that this should be published, including review for confidential internal information?
6. What is the name of your L2 for approval? Please add to Reviewer field.
7. Should this be distributed on Avg Jo's social channels?
8. Did someone from your group's comms team review and edit the content?
9. Is there an embargo date (don't publish before) or deadline (must publish by)? Please set Due Date to desired publish date""".replaceAll(/ /, '')

def defaultValue2 = """Request to publish public engineering blog post for <project or team name>???""".replaceAll(/ /, '')

if (labelVal.toString().contains("Publish_Blog") && compVal.toString().contains("Open Source") && getActionName() in ["Create Issue", "Create"]) {
desc.setFormValue(defaultValue)
summary.setFormValue(defaultValue2)
}

 No luck, unfortunately :(

Screen Shot 2020-08-27 at 12.16.21 PM.png

I do have this set as the initialiser for this behaviour though. Could that be the issue?

What happens if you create an issue with an empty description field using the component?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

51 views 0 3
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