Forums

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

three number custom fields

RichardA February 21, 2020

All the values of these custom fields must be appear in the fourth custom field before creating the issue.

Ex : user enter the value in custom field A is 1

B is 2

C is 3

1+2+3-->6

 

Final value is appear in fourth custom field before creating the issue...(6)

Can you guys are help me out this issue for how to do in groovy scripting.

2 answers

0 votes
RichardA April 21, 2020
0 votes
Pete Singleton
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.
February 21, 2020

You need to get the custom field IDs first, you can get this by editing the custom field configuration, the ID will be shown in your browser URL.  Once you have the custom field IDs, you can create a script for your 4th field with something like this:

fieldA = issue.get("customfield_xxx");
fieldB = issue.get("customfield_yyy");
fieldC = issue.get("customfield_zzz");

return fieldA + fieldB + fieldC;

Substitute the xxx, yyy and zzz for your specific custom field IDs.  If you want to protect against null values, you can do this:

fieldA = issue.get("customfield_xxx") != null ? issue.get("customfield_xxx") : "0";
fieldB = issue.get("customfield_yyy") != null ? issue.get("customfield_yyy") : "0";
fieldC = issue.get("customfield_zzz") != null ? issue.get("customfield_zzz") : "0";

return fieldA + fieldB + fieldC;
RichardA February 21, 2020

Hi @Pete Singleton  Thanks For your Response. i am trying to execute the code you are given but it shows some error 

9.jpg

Pete Singleton
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.
February 21, 2020

Which plugin are you using to execute the script?  Can you post the entire script you are using?

RichardA February 21, 2020

I am using script runner  Plugin Version 5.6.14.1-p5

 

 

 

Pete Singleton
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.
February 21, 2020

Try this

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;

def cfM = ComponentAccessor.getCustomFieldManager()

def QuantityOnHoldCF = cfMan.getCustomFieldObject("customfield_11518");
int QuantityOnHoldCFValue = (int) issue.getCustomFieldValue(QuantityOnHoldCF);

def quaCF = cfMan.getCustomFieldObject("customfield_11519");
int quaCFValue = (int) issue.getCustomFieldValue(quaCF);

def abcCF = cfMan.getCustomFieldObject("customfield_11517");
int abcCFValue = (int) issue.getCustomFieldValue(abcCF);

return QuantityOnHoldCFValue  + quaCFValue + abcCFValue 
RichardA February 21, 2020

hi @Pete Singleton  again its showing error 

Pete Singleton
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.
February 21, 2020

It seems ComponentManager has been deprecated with Jira 8.  Just remove that line (3) and it should work

Pete Singleton
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.
February 21, 2020
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;

def cfM = ComponentAccessor.getCustomFieldManager()

def QuantityOnHoldCF = cfM.getCustomFieldObject("customfield_11518");
int QuantityOnHoldCFValue = (int) issue.getCustomFieldValue(QuantityOnHoldCF);

def quaCF = cfMan.getCustomFieldObject("customfield_11519");
int quaCFValue = (int) issue.getCustomFieldValue(quaCF);

def abcCF = cfMan.getCustomFieldObject("customfield_11517");
int abcCFValue = (int) issue.getCustomFieldValue(abcCF);

return QuantityOnHoldCFValue  + quaCFValue + abcCFValue   
RichardA February 22, 2020

 

How to set SumValue in Fourth field ...?

 

Pete Singleton
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.
February 23, 2020

Have you tried the code I posted??

RichardA February 23, 2020

Tried but getting so many errors

Pete Singleton
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.
February 25, 2020

Ok, I've just tested the script below using my instance and ScriptRunner, it works.  You will need to change the custom field IDs to the correct ones for your instance:

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.component.ComponentAccessor;

def cfM = ComponentAccessor.getCustomFieldManager()

def QuantityOnHoldCF = cfM.getCustomFieldObject("customfield_10301");
int QuantityOnHoldCFValue = (int) issue.getCustomFieldValue(QuantityOnHoldCF);

def quaCF = cfM.getCustomFieldObject("customfield_10302");
int quaCFValue = (int) issue.getCustomFieldValue(quaCF);

def abcCF = cfM.getCustomFieldObject("customfield_10303");
int abcCFValue = (int) issue.getCustomFieldValue(abcCF);

return QuantityOnHoldCFValue + quaCFValue + abcCFValue
RichardA April 14, 2020

Hi@Pete_Singleton

Can you help me out this issue

Thanks.

Suggest an answer

Log in or Sign up to answer