How to save an Issue as a custom field with IssueInputParameters

Martin Bom November 17, 2017

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 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 17, 2017

The epic link is not an issueimpl. 

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

Martin Bom November 17, 2017

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?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 17, 2017

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...

Martin Bom November 17, 2017

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/

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 17, 2017

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)

Martin Bom November 17, 2017

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

Martin Bom November 18, 2017

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!

Martin Bom November 29, 2017

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
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.
November 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.

Martin Bom November 17, 2017

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

Alexey Matveev
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.
November 17, 2017

Try this

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

Suggest an answer

Log in or Sign up to answer