Forums

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

three number custom fields

RichardA February 21, 2020 edited

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 edited
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 edited

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 edited

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 edited

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 edited

 

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 edited

Hi@Pete_Singleton

Can you help me out this issue

Thanks.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian community, loom ai, atlassian loom ai, loom, atlassian ai, record recaps of meetings, meeting recaps, loom recaps, share meeting recaps,

Loom’s guide to great meetings 📹

Join us to learn how your team can stay fully engaged in meetings without worrying about writing everything down. Dive into Loom's newest feature, Loom AI for meetings, which automatically takes notes and tracks action items.

Register today!
AUG Leaders

Atlassian Community Events