Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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 

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)

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)
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

162 views 1 1
View question

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