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,461,662
Community Members
 
Community Events
176
Community Groups

Condition to dont change field when field is set by user

Edited

Hi,

i have a script (made with scriptrunner) in Jira. This script works only when new issue is created. Script takes fields values from epic and copy to the story/task ... but this script working also when user change field than i need condition to script dont do anything with a certaint fields when this fields has been set by user when user is creating a issue.

I have conditions like this if (epic != null) {
if (field_team != null) {

Is posible to make another condition to check if user set the value (in creating screen) and when set dont do anything?

Can someone please help me?

3 answers

1 accepted

0 votes
Answer accepted

ok i have a solution > 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def field_epicLink = customFieldManager.getCustomFieldObject(10001)
def epic = issue.getCustomFieldValue(field_epicLink) as Issue

def field_team = customFieldManager.getCustomFieldObject(10300)
def field_productArea = customFieldManager.getCustomFieldObject(10502)

def team = issue.getCustomFieldValue(field_team)
def productArea = issue.getCustomFieldValue(field_productArea)

if (epic != null) {
if (team == null){
if (field_team != null) {
def value_team = epic.getCustomFieldValue(field_team)
issue.setCustomFieldValue(field_team, value_team)
}
}
if (productArea == null){
if (field_productArea != null){
def value_productArea = epic.getCustomFieldValue(field_productArea)
issue.setCustomFieldValue(field_productArea, value_productArea)
}
}
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

}

 

Thanks everyone for help 

This is the code >>> Is posible to make another condition to check if user set the value (in creating screen) and when set dont do anything?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def field_epicLink = customFieldManager.getCustomFieldObject(10001)
def epic = issue.getCustomFieldValue(field_epicLink) as Issue

def field_team = customFieldManager.getCustomFieldObject(10300)
def field_productArea = customFieldManager.getCustomFieldObject(10502)

if (epic != null) {
if (field_team != null) {
def value_team = epic.getCustomFieldValue(field_team)
issue.setCustomFieldValue(field_team, value_team)
}

if (field_productArea != null) {
def value_productArea = epic.getCustomFieldValue(field_productArea)
issue.setCustomFieldValue(field_productArea, value_productArea)
}

issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}

Ok i know how to do but i have a error while compiling : 

2019-02-21 10:05:54,844 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-02-21 10:05:54,845 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CFDP-5382, actionId: 1, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.ImmutableCustomField) values: [Team]
 at Script573.run(Script573.groovy:17)

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events