help in conditional field based on two other fields

Sam May 12, 2020

Hello,

I'm currently creating a prototype to evaluate JIRA and ScriptRunner, and have some issues I need to learn about.
1- How do I set a "number field" to display values based on another field's value based on the condition  when updating an issue.

here field A and field B are number fields.
If field A > 0 & Field B <0

then field C = yes
2- Also , 

If field A < 0 & Field B >0

then field C = no

Thank you,

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Alejandro Suárez - TecnoFor
Atlassian Partner
May 28, 2020

Hi @Sam Here you go:

import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cfA = customFieldManager.getCustomFieldObject(12456L) //Your number CustomField A
CustomField cfB = customFieldManager.getCustomFieldObject(12456L) //Your number CustomField B
CustomField cfC = customFieldManager.getCustomFieldObject(12456L) //Your number CustomField C

Double aValue = cfA.getValue(issue) as Double
Double bValue = cfB.getValue(issue) as Double

if (aValue > 0 && bValue < 0) {
issue.setCustomFieldValue(cfC, "yes")
} else if (aValue < 0 && bValue > 0) {
issue.setCustomFieldValue(cfC, "no")
}

ComponentAccessor.getIssueManager().updateIssue(
ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),
issue,
EventDispatchOption.ISSUE_UPDATED,
false
)

 I'm assumed that your CustomField "C" is a Text Field.

Sam May 28, 2020

Thank You Alejandro. It is working.

TAGS
AUG Leaders

Atlassian Community Events