get customfield value based on issue type Jira

orgest April 13, 2015

Hello

i want to create a script where i can get customfield value based on issue type Jira.

 

Please, can help me anyone ??

4 answers

1 accepted

0 votes
Answer accepted
Peter Bengov
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.
April 13, 2015

You have 2 good options of doing so:

Example of how you can do that using the 2nd option (1st option is similar):

<!-- @@Formula: 
String issueType = issue.get("issuetype").getName().toString();
if (issueType.equals("Task")) {
   return issue.get("customfield_12600");
}
-->
0 votes
orgest April 16, 2015

why this code work only for the first condition.

For other condition it is not working.

 

 

<!-- @@Formula:
String issueType = issue.get("issuetype").getName().toString();
if ((issue.get("customfield_13027").equals("L")) && (issueType.equals("Money Market")))
{ return issue.get("customfield_10010"); }

else if ((issue.get("customfield_13027").equals("B")) && (issueType.equals("Money Market")))
{ return ((issue.get("customfield_10010")) + (issue.get("customfield_10013"))); }

else if (issueType.equals("Forex Spot"))
{ return issue.get("customfield_12371"); }

else if (issueType.equals("Cash against account"))
{ return issue.get("customfield_12406").toString(); }

else if ((issue.get("customfield_12413").equals("REPO")) && (issueType.equals("Repo/Rev.Repo")))
{ return issue.get("customfield_12417"); }

else if ((issue.get("customfield_12413").equals("Rev.REPO")) && (issueType.equals("Repo/Rev.Repo")))
{ return ((issue.get("customfield_12417")) + (issue.get("customfield_12422"))); }


else if (issueType.equals("Primary Market Treasury Bills in ALL"))
{ return issue.get("customfield_12450"); }

else if (issueType.equals("Primary Market Treasury Bills in EUR"))
{ return issue.get("customfield_12465"); }

else if (issueType.equals("Treasury Bills in ALL from Banks"))
{ return issue.get("customfield_12481"); }

else if (issueType.equals("Treasury Bills in ALL from Customers"))
{ return issue.get("customfield_12497"); }

else if (issueType.equals("Bonds ALL"))
{ return issue.get("customfield_12518"); }

else if (issueType.equals("Bonds ALL from Banks"))
{ return issue.get("customfield_12351"); }

else if (issueType.equals("EUROBonds from Banks"))
{ return issue.get("customfield_12534"); }

else if (issueType.equals("Open Funds BSH"))
{ return issue.get("customfield_12336"); }

else if (issueType.equals("Fund Transfer"))
{ return issue.get("customfield_12320"); }

else if (issueType.equals("Obligatory Reserve"))
{ return issue.get("customfield_12328"); }

else if (issueType.equals("Cash Deposit BSH"))
{ return issue.get("customfield_13131"); }

-->

0 votes
orgest April 14, 2015

I am using this code, but it is not working 

 

 

<!-- @@Formula:
String issueType = issue.get("issuetype").getName().toString();

if ((issue.get("customfield_13027").equals("L")) && (issueType.equals("Money Market")))

{ return issue.get("customfield_10010"); }

else if ((issue.get("customfield_13027").equals("B")) && (issueType.equals("Money Market")))

{ return ((issue.get("customfield_10010")) + (issue.get("customfield_10013"))); }

else if (issueType.equals("Forex Spot"))

{ return issue.get("customfield_12371"); }

else if (issueType.equals("Cash against account"))

{ return issue.get("customfield_12406"); }

else if ((issue.get("customfield_12413").equals("REPO")) && (issueType.equals("Repo/Rev.Repo")))

{ return issue.get("customfield_12417"); }

else if ((issue.get("customfield_12413").equals("Rev.REPO")) && (issueType.equals("Repo/Rev.Repo")))

{ return ((issue.get("customfield_12417")) + (issue.get("customfield_12422"))); }

-->

Peter Bengov
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.
April 14, 2015

What type of calculated field is it? Text? Number? Try adding .toString() to each of your return statements. Example: { return issue.get("customfield_10010").toString(); } For debugging, you can add some log.warn(issue.get("customfield_10010")) to see what is returned by this field.

orgest April 14, 2015

it is Calculated Number Field

orgest April 14, 2015

Again it not working..... it is working for this condition... else if ((issue.get("customfield_13027").equals("B")) && (issueType.equals("Money Market"))) { return ((issue.get("customfield_10010")) + (issue.get("customfield_10013"))); } but do not work for other confition .... else if ((issue.get("customfield_12413").equals("REPO")) && (issueType.equals("Repo/Rev.Repo"))) { return issue.get("customfield_12417"); }

Peter Bengov
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.
April 15, 2015

Can you make sure that REPO is the exact value of customfield_12413? Myabe it has a space after O, like "REPO ". Also, the special characters in Repo/Rev.Repo issue type might need some escaping. Add some log.warn to see the log and go to tickets that should be working for the condition, that way we'll see how the data is saved.

0 votes
orgest April 14, 2015

can I use if else here ?

 

Peter Bengov
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.
April 14, 2015

yes

orgest April 14, 2015

Please, can you help me with code syntax ? any example for 2 different issue types ??

Peter Bengov
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.
April 14, 2015

{code} <!-- @@Formula: String issueType = issue.get("issuetype").getName().toString(); if (issueType.equals("Task")) { return issue.get("customfield_12600"); } else if (issueType.equals("Story")){ return "this is a story ticket"; } --> {code}

Suggest an answer

Log in or Sign up to answer