How to access "sourceIssue" during validator for cloned issue using java api?

Tagged with ScriptRunner as I know that plugin has made this available as 'sourceIssue' - wondering how to get that information when using the underlying api.

I've tried accessing fields via issue, and both the issue and originalissueobject in transientVars - but no luck for either - either the object reference is null or the particular field returns no value - or I get the exception about issue having not been saved yet.

Hoping Jamie Echlin can provide details on where that field in ScriptRunner is retrieving this object from or any other suggestions. 

3 answers

This widget could not be displayed.

Hi Nathan,

If i understand the question you are asking how to access the issue in a custom jira workflow extension.

If that's the case:

when you implement the interface WorkflowPluginValidatorFactory you need to provide a concrete implementation of the validate method, this method needs an parameter of type Map called transientVars, from this map you get the issue being validated.

Here's the example:

https://developer.atlassian.com/jiradev/jira-platform/guides/workflow/tutorial-creating-workflow-extensions#Tutorial-Creatingworkflowextensions-Part3.Createavalidator

 

Gaston Valente Community Champion Jul 27, 2017

This is the code sample, i cannot add it to the previous answer:


public void validate(Map transientVars, Map args, PropertySet ps) throws InvalidInputException
{
Issue issue = (Issue) transientVars.get("issue");
if(null == issue.getFixVersions() || issue.getFixVersions().size() == 0)
{
throw new InvalidInputException("Issue must have a fix version");
}

 

This widget could not be displayed.

Nope - I got that part... That's easy (have lots of other validation rules implemented). 

 

I'm specifically looking for how to get at the original/source issue during a validation when an issue _clone_ is taking place.

 

I actually don't really care about the original issue so much as being able to access the 'reporter' information from it. Accessing reporter with issue.getString("reporter") works fine in the case of creating a new issue or an update to an existing issue - but when doing it on a cloned issue I get an exception that the issue hasn't been saved yet.

hmm... just noticed that at least for reporter and assignee there are built in accessors - going to try using them to see if symptom changes. 

Gaston Valente Community Champion Jul 27, 2017

Nathan, sorry about the misunderstanding, how are you clone the issue? are you using issueFactory?

User driven from the web UI using 'Clone Issue'

Ok. It appears for this particular case, using the accessors for these two particular fields appears to work, so this whole question may be moot. 

This widget could not be displayed.

Unfortunately, now have hit up against a case where the above does NOT work. Seems like getDescription() doesn't work in the clone case, unlike getReporter and getAssignee

For now, I'm modifying my validation to just ignore cloned issues, but that's not really a solution.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

575 views 25 15
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