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,551,873
Community Members
 
Community Events
184
Community Groups

Update the summary value if the chosen priority is "High" when creating issue

Hey! My goal is to update the summary by adding a word "Important" at the beginning of the summary if the selected priority is "High". I am doing this with ScriptRunner by creating a behaviour. I create a mapping for the behaviour with choosing all "issue types". I did not add any field and just add a initialiser scpt. Please see the script below. It has no error but it is failing to update the summary when I set the priority to High when creating issue. 

```

import com.onresolve.scriptrunner.runner.util.UserMessageUtil

def priorityField = getFieldById("priority")
def summaryField = getFieldById("summary")

log.debug(priorityField.getValue()?.toString())

// Check if the chosen priority is "High"
if (priorityField.getValue()?.toString() == "High") {
def summaryValue = summaryField.getValue() as String
log.debug(summaryValue)

// Add "Urgency: " prefix to the summary
def updatedSummary = "Urgency: $summaryValue"
summaryField.setFormValue(updatedSummary)
} else {
// Show a warning message if the priority is not "High"
UserMessageUtil.warning("This behavior only applies when Priority is set to High.")
}

```

2 answers

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 22, 2023 • edited

Hi @Naheem Olaniyan

After reviewing your code, it will not work as expected. If you look through your if/else conditions, you cannot get the Priority's name directly. You will have to use its Priority ID, i.e. a numeric value if you are using your approach.

You will need to configure a Server-Side Behaviour for the Priority field and modify your slightly to:-

import com.atlassian.jira.issue.IssueConstant
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def priorityField = getFieldById(fieldChanged)
def priorityValue = priorityField.value as IssueConstant
def summaryField = getFieldById("summary")

log.debug(priorityValue)

// Check if the chosen priority is "High"
if (priorityValue.name == "High") {
def summaryValue = summaryField.getValue() as String
log.debug(summaryValue)
// Add "Urgency: " prefix to the summary
def updatedSummary = "Urgency: $summaryValue"
summaryField.setFormValue(updatedSummary)
} else {
// Show a warning message if the priority is not "High"
UserMessageUtil.warning("This behavior only applies when Priority is set to High.")
}

If you notice the updated code above, instead of using priorityField.getValue()?.toString() == "High", I am converting the Priority field's value into an IssueConstant.

From there I am able to use the name and compare it against either High, Low, Lowest, Blocker etc in the if/else condition.

Below is a screenshot of the Behaviour configuration:-

behaviour_config-1.png

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

This is really helpful. Thanks

Hi Mikel,

The initialiser script is called when the dialog is shown - and at that point the user has not selected a priority. What you need to do is to add the 'Priority' field and add your script as a server-side script for that field. That way your code will get executed whenever the user selects a value for the'Priority' field. 

Br, Sune

Thanks for the clarification

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events