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
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.