How to apply Create Constrained Issue to the "current" project - Scriptrunner

Jodi Gornick February 28, 2017

I would like to use the functionality that is described in the Adaptivist documentation for how to create a constrained issue. I would like to have this apply to all projects in the system, but the project selection to be the "current project" where the menu item is selected from.

https://scriptrunner.adaptavist.com/latest/jira/fragments/CreateConstrainedIssue.html

It appears that I can only select a specific project which would mean this would have to be set up potentially for every project?  

If this is not the right way, then can anyone advise an alternative?

Our Use Case is that we would like users to have the ability to create a new issue (defect) from an enhancement (that caused the defect) and link them together.  We would like this functionality for all projects where Enhancements are part of the scheme. 

We have alternative use cases of creating a Request for Change from a Problem issue type - but the functionality is the same.

Thank you in advance!

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Jonny Carter
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.
February 28, 2017

So, the Project drop-down is required for the Create Constrained Issue dialog fragment, and it specifies the destination project.

For your use case, it sounds like you'll want the defect issue to always be in the same project as the enhancement. If that's correct, then I think you could set this up with a plain custom web item. You'll notice that the fields are pretty similar, since the Constrained Issue fragment extends the custom web item behind the scenes.

The main trick is that for the action, you'll choose Navigate to a Link. For the link, you'll enter a relative URL like this:

/secure/CreateIssue.jspa?pid=$issue.projectObject.id&issuetype=10001

Just replace the issuetype parameter (10001) with the ID of your Defect issue type. You can get that ID from the edit link for that particular type in the Issue Types admin page.

For your condition, you'll want something like 

 

issue.issueType.name == "Enhancement"

so that the button only shows up on Enhancement requests.

You'll still setup the behaviour as described in the Create Constrained Issue documentation.

Ramandeep Sandhu May 7, 2018

Hi Jonny,

With your suggested approach, is it possible to use Behavior plugin to set preset values in the form. Doesn't seem to work like the way it does for Dialogs. Specifically, there is no access to BehaviorContextId and contextIssueId.

Thanks in advance,

Ramandeep Sandhu

Jonny Carter
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.
May 7, 2018

That's right, Ramandeep. Those variables are only set in the create constrained issue context. That said, there is an issueContext variable in the binding that will get you the same information (project & issue type). Whenever you're in the edit view, there's also an underlyingIssue variable to represent the issue in the database; notably, underlyingIssue is null on the create issue screen, since there is no saved issue yet.

Ramandeep Sandhu May 7, 2018

Thanks for the reply Jonny. 

So how do I restrict the behavior to run only if the user clicked a custom webitem that I have added ?

Jonny Carter
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.
May 7, 2018

We don't currently have a good means for doing stuff like that outside of Create Constrained Issue. We do have an issue in the backlog for it: https://productsupport.adaptavist.com/browse/SRJIRA-2180

Ramandeep Sandhu May 7, 2018

Okay.

So as a workaround, is it possible to change the Project value using a behavior, when the Create Constrained Issue dialog opens ?

Jonny Carter
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.
May 7, 2018

Full disclosure: Interacting with the project field or issue type field with a Behaviour is a bit dodgy. The reason is that as soon as you change projects, the behaviours context changes. Recall that all behaviours are mapped using Project and issue Type (or service desk and request type on the Service Desk side). 

There are a fair number of open issues related to this, https://productsupport.adaptavist.com/browse/SRJIRA-2356 and https://productsupport.adaptavist.com/browse/SRJIRA-2737 being noteworthy among them.

While I think you technically can set the value of a project field in certain contexts using a behaviour, you're likely to create headaches for yourself, as the behaviour context is immediately going to change when you do. In the Create Constrained Issue context, whatever project you set in that Script Fragment's configuration is going to be what you should expect. You might be able to use conditions to manage multiple, non-intersecting Create Constrained Issue fragments, but I'm not even sure exactly what you're trying to accomplish.

Less is often more with Behaviours. As someone who's been there fairly often, I'd recommend you take a step back and think about what you're really after before you build a house of cards. ;)

Ramandeep Sandhu May 7, 2018

Thanks for the detailed explanation Jonny. 

Well, what I was trying to do was to add a shortcut to Create Linked Documentation type Issue for an issue. While using the Create Constrained Issue Fragment, I found that it needs a Project to be specified. Since we have multiple Projects, I was trying to avoid creating these fragments for each and every project - that is certainly hard to maintain.

So I was just trying to figure out If I could implement it in a generic manner for all the projects. Seems like there isn't a way to do that currently unless https://productsupport.adaptavist.com/browse/SRJIRA-2180 gets fixed.

Thanks for your reply.

TAGS
AUG Leaders

Atlassian Community Events