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 Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Amir Kazemi
Posted an hour ago in Jira

We want to know what Jira Service Desk apps you're using!

Hi Community! My name is Amir and I’m on the Jira Service Desk product marketing team at Atlassian. Our team would love to understand how you’re leveraging our ecosystem for Jira Service Desk. Wha...

9 views 0 2
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