You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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.
```
```
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:-
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.