get customfield value based on issue type Jira

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
Accepted answer
Peter Bengov Community Champion Apr 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");
}
-->

can I use if else here ?

 

Peter Bengov Community Champion Apr 14, 2015

yes

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

Peter Bengov Community Champion Apr 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}

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 Community Champion Apr 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.

it is Calculated Number Field

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 Community Champion Apr 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.

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"); }

-->

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,417 views 15 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you