Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

saravanan subramanian
Contributor
October 22, 2015

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
Answer accepted
Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 27, 2015

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

 

saravanan subramanian
Contributor
November 3, 2015

Thanks for your help . worked out great :)

0 votes
saravanan subramanian
Contributor
October 23, 2015

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

0 votes
Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2015

Hi @saravanan subramanian Is this a behaviour script ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events