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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,559,882
Community Members
 
Community Events
185
Community Groups

help in conditional field based on two other fields

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

0 votes
Answer accepted
Alejandro Suárez
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.
May 28, 2020 • edited

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.

Thank You Alejandro. It is working.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events