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,297,305
Community Members
 
Community Events
165
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
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

352 views 0 10
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you