Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set Summary and Description based on label and component values

Ian Balas August 26, 2020

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
Jeff Gordon
Contributor
December 20, 2021

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.

0 votes
Raynard Rhodes
Contributor
August 27, 2020
Ian Balas August 27, 2020

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?

Raynard Rhodes
Contributor
September 2, 2020

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