Set the multiline field mandatory only when the select list is changed and during only Edit action

hi all,

 

I received the following code snippet from a user in this forum, this works great but it fires even when the select list is not changed. is it possible to fire this only when the select list value changed and during the edit action of the issue ?  Please let me know.

 

// Get a pointer to both my fields
def demoSelect = getFieldByName("Demo Select List")
def demoMultiTxt = getFieldByName("Demo Multi Line Text Field")
// Get the Value of the Select List Field
def selectedVal = demoSelect.getValue()
if (selectedVal != null){
demoMultiTxt.setRequired(true)
}

3 answers

1 accepted

1 vote
Accepted answer

Hi @saravanan subramanian

You can get the original value of the issue's custom field using underlyingIssue. For example in your case should be :

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = underlyingIssue
def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Demo Select List"}

// Get a pointer to both my fields
def demoSelect = getFieldByName("Demo Select List")
def demoMultiTxt = getFieldByName("Demo Multi Line Text Field")

// Get the Value of the Select List Field
def selectedVal = demoSelect?.getValue()
def previousVal = tgtField?.getValue(issue)

if (selectedVal?.toString()?.equalsIgnoreCase(previousVal?.toString())) {
log.debug("Values are the same I will set the require to false")
demoMultiTxt?.setRequired(false)
} else {
log.debug("Values are different I will set the require to true")
demoMultiTxt?.setRequired(true)
}

 

Thanks for your help . worked out great :)

Hi @saravanan subramanian Is this a behaviour script ?

Hi @Thanos Batagiannis [Adaptavist] Yes - it is . Please help me out

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,319 views 0 8
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you