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.
I'm trying to use Behaviours plugin to set default value for some custom fields when create issue.
I created Behaviour and added script
import com.atlassian.jira.component.ComponentAccessor
def tasksFld = getFieldByName("Tasks")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(tasksFld.getFieldId())
def defaultValue = """[Tasks|https://]""".replaceAll(/ /, '')
if (getFieldScreen().name == "RM CreateScreen 2.0") {
tasksFld.setFormValue(defaultValue)
}
but I did not get needed result - seems like condition
getFieldScreen().name == "RM CreateScreen 2.0"
never works. It does not put value to field when issue created and screen "RM CreateScreen 2.0" is used.
Am I doing something wrong?
Maybe there is another method to restrict behaviours only for create issue operation? Or don’t overwrite the custom field if it already exists?
resolved with
if (getAction()?.id != 1) {
return // not the initial action, so don't set default values
}
Hello,
I guess the problem is with getFieldScreen().name == "RM CreateScreen 2.0". Are you sure that your create screen is called "RM CreateScreen 2.0"? You can verify it by logging the name of the screen in the behavour. For example you could add to the beginning of your behavour log.error("getFieldScreen().name") and have a look in atlassian-jira.log what the name of the screen is.
But do not do it. Better use another function which is getActionName(). This function always returns the transition name. In your case it will be "Create Issue". Try to replace your code with this one:
if (getActionName() == "Create Issue") {
tasksFld.setFormValue(defaultValue)
}
It must work.
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.