How to save an Issue as a custom field with IssueInputParameters Edited

Wrote a plugin to auto create several tasks linked to an Epic. Now trying to assign these created tasks to the Epic (I also link them but assigning them to the Epic makes it easier to use). I can see the "Epic Link" and "Epic Name" custom field values and noticed that Greenhopper is using IssueImp for the Epic Link custom field: XX-1234 (toString) class com.atlassian.jira.issue.IssueImpl (getCLass.toString)

I am using IssueInputParameters to create my tasks. Just using addCustomFieldValue on "Epic Link" to add the Epic Issue (Issue class) to indicate that these created tasks are in the Epic does not work. Using a MutableIssue of the Issue as data to store does not work either: error: no suitable method found for addCustomFieldValue(String,  MutableIssue / Issue / Object

What is the right way to store a complex object like IssueImp or Issue as a custom field? I personally would store a key as link in a custom field but because this needs to work with Greenhopper I need to store it in the same format so I can't change that approach. Thanks!

 Edit:

Examples were asked:

IssueInputParameters issueIP = this.issueService.newIssueInputParameters();

issueIP.setProjectId(projectID);

......

issueIP.setFixVersionIds(fixVersionId);
issueIP.setApplyDefaultValuesWhenParameterNotProvided(true);

issueIP.addCustomFieldValue("Epic Link", (Object) issueManager.getIssueObject("XX-1234"));

IssueService.CreateValidationResult issueinput = issueService.validateCreate(user, issueIP);

 

Compile error:

error: no suitable method found for addCustomFieldValue(String,Object)

Trying  Issue:

issueIP.addCustomFieldValue("Epic Link", Issue);

will result in 

error: no suitable method found for addCustomFieldValue(String,Issue)

Similar for MutableIssue

2 answers

1 accepted

1 votes

The epic link is not an issueimpl. 

You can use EpicLinkManager.associateIssuesWithEpic( <epic>, <list of issues> ) to associate the issue with the Epic.

Thanks Nic! I was looking for storing more Objects than just the example for Epic above but I would definitely prefer to use that API for the Epic linking. I am surprised you mentioned that it is not a IssueImp as thats what I got back from a getClass.toString().

 

Any advice you can give in regards to storing any other complex objects or is the addCustomField pretty much only accepting String input?

Most custom fields need objects that represent their content.  For numbers, that's easy - int, long and doubles can all go in.  Text fields expect strings, dates expect Timestamps, and so-on.  The Jira specific types are ones like users and "options" (for most fields that are selects or radio or checkmarks).  Field with multiple values need arrays of those objects.  So a select list expects one option, and a multi-select expects an array of options

Although I have a nagging doubt that some of them changed slightly recently - select lists may be expecting singleton objects containing one option.  I need to dig that code out...

Thanks Nic, that explains a lot and will help with my other items for the auto created tasks!

Concerning greenhopper, I can add jira-greenhopper-plugin to my pom.xml however com.atlassian.greenhopper.manager is not in that jar and cannot be imported 5.6.2 from https://maven.atlassian.com/repository/public/greenhopper/jira-greenhopper-plugin/

The greenhopper stuff is really very old, and you should be importing Jira Software stuff really (Although it's not been refactored in full, so there are references to GH and Agile in it still)

Thanks! I cannot find the EpicLinkManager in any other package, am I missing an obvious newer version?

Never mind, copy paste mistake:

<dependency>
<groupId>com.atlassian.jira.plugins</groupId>
<artifactId>jira-greenhopper-plugin</artifactId>
<version>6.7.4</version>
<scope>provided</scope>
</dependency>

took care of it

Thanks!

I have been trying to complete this call but I have reached a dead end. I am unable to inject the EpicLinkManager or the EpicLinkManagerImpl class. At this point I simply create a EpicLinkManagerImpl and then call a getEpic of that new class. That crashes though even if the issue has an epic link:

[INFO] [talledLocalContainer] 2017-11-29 18:59:51,763 http-nio-2990-exec-3 ERROR [o.a.c.c.C.[.[localhost].[/jira].[action]] Servlet.service() for servlet [action] in context with path [/jira] threw exception [java.lang.NullPointerException] with root cause
[INFO] [talledLocalContainer] java.lang.NullPointerException
[INFO] [talledLocalContainer] at com.atlassian.greenhopper.manager.issuelink.EpicLinkManagerImpl.getEpicLinkType(EpicLinkManagerImpl.java:484)
[INFO] [talledLocalContainer] at com.atlassian.greenhopper.manager.issuelink.EpicLinkManagerImpl.getEpic(EpicLinkManagerImpl.java:79)

What am I doing wrong?

0 votes
Alexey Matveev Community Champion Nov 17, 2017

Hello, 

If you provided a script which does not work, it would be simpler to answer and if the script was straight to the point, it would be even  simpler.

I just added the snippets in question, with a very straight to the point code sample

Alexey Matveev Community Champion Nov 17, 2017

Try this

issueIP.addCustomFieldValue("Epic Link", issueManager.getIssueObject("XX-1234").getKey());

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Feb 15, 2018 in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

1,065 views 6 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
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