HI,
I want to add two customfield values and have to display that in another customfield. for example, in our project we have 3 fields called TEST1, TEST2 and TEST3. Want to add Test1 and Test2 and that has to be displayed in Test3. These 3 fields are number fields. Can you please share any codes to perform this ? And after that, the value of TEST3 , we have to show that in the dashboard.
Thanks,
Hi @Nirmala,
You can go with scriptrunner's behaviour which will capture value from another field and set another field value in the same screen
def field1 = getFieldByName("Test1")
def field2 = getFieldByName("Test2")
def field3 = getFieldByName("Test3")
def value1 = field1.getFormValue() as Double
def value2 = field2.getFormValue() as Double
def value = value1 + value2
field3.setFormValue(value)
field3.setReadOnly(true)
I haven't tried this code, it may need some minor changes
BR,
Leo
Hello,
Something like this should work:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
//def issue = issueManager.getIssueObject("OT-3")
def userManager = ComponentAccessor.getUserManager()
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def user = authenticationContext.getLoggedInUser()
def test3CF = customFieldManager.getCustomFieldObject("customfield_10240") //change cf id
def test1CF = customFieldManager.getCustomFieldObject("customfield_10323") //change cf id
def test2CF = customFieldManager.getCustomFieldObject("customfield_10324") //change cf id
def test1value = test2CF.getValue(issue) == null ? 0 : test1CF.getValue(issue)
def test2value = test2CF.getValue(issue) == null ? 0 : test2CF.getValue(issue)
def test3value = (double)test1value + (double)test2value
issue.setCustomFieldValue(test3CF, test3value)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
return test3value
issue.store()
Regards,
Elifcan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Can you please suggest where to add these condition ,like in the workflow or is this something different? Because i'm new to this.
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
You can add it to the postfunction of your workflow if it will be only updated via transition. Or you can add it as script listener that listens to issue updated event and updates whenever one of these two customfield changes.
Regards,
Elifcan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
But we are trying to populate this on the create screen itself. is that be possible to display the total value in the create screen itself with non editable one. because we have to display that in the dashboard. Can you please suggest any idea for this?
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Sorry, I didn't see your comment. You can use @Leo 's solution or use a script field that comes from Script Runner plugin. Script field also shows the changes on the same screen as far as I know.
Regards,
Elifcan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.