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

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 ?

 

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

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

-->

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

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,798 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot