Scriptrunner web fragments for creating subtask with default values

Filip Håkansson January 31, 2017

Hello,

Is it possible to open a Create Sub-Task screen from a web item button in Scriprunner?

Background:

We would like to have a button on an issue to create a subtask of a specific type.

As far as I can see only Create issue is supported, not create subtask.

 

Best regards

Filip

 

2 answers

1 accepted

2 votes
Answer accepted
JamieA
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 3, 2017

I've added a bit to the docn. It's not ideal but might be good enough for you.

You may wish to create a subtask of the current issue (or any other issue) at a particular stage.

We currently don’t have support via the UI for this (SRJIRA-2162). But you can do it with a raw XML fragment, with the caveat that the form will open in full-screen mode.

Reminder, pressing the Preview button generates the XML for any web fragment, which you can modify and submit via the raw xml module built-in script.

The XML to use is for example:

<web-item key='link-create-subtask' name='ScriptRunner generated web item - create-subtask' section='operations-operations' weight='1'>
    <label>Create Linked Subbie</label>
    <link linkId='link-create-constrained-subtask'>/jira/secure/CreateSubTaskIssue.jspa?parentIssueId=${issue.id}&amp;pid=${issue.projectObject.id}&amp;issuetype=10004</link>
</web-item>

 

Set the issue type ID of the subtask, and set the context path correctly, in the case of the example above it is /jira.

Filip Håkansson February 3, 2017

Thank you Jamie.

We tried it now.

It works, but the full-screen mode is not beautiful.

Do you think it will be possible to solve with a dialog like the built-in create-subtask? (if/when SRJIRA-2162 is implemented)

 

 

Like PRIADUNENKO_ IHOR likes this
JamieA
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 3, 2017

yeah that's the main task of that issue.

Max Lim -Adaptavist- January 11, 2021

To make as a dialog like the built-in create-subtask, you need to add a class:

<styleClass>issueaction-create-subtask</styleClass>

So, add on the XML example by @JamieA, it becomes: 

<web-item key='link-create-subtask' name='ScriptRunner generated web item - create-subtask' section='operations-operations' weight='1'> <label>Create Linked Subbie</label>
<styleClass>issueaction-create-subtask</styleClass>
<link linkId=
'link-create-constrained-subtask'>/jira/secure/CreateSubTaskIssue.jspa?parentIssueId=${issue.id}&amp;pid=${issue.projectObject.id}&amp;issuetype=10004</link>
</web-item>
Like # people like this
Jared Dohrman {ANZ} August 8, 2021

The only problem with this is that if you have multiple Sub-task issue types, even by specifying the ID, it will always default to what the user selected last time when creating.

Like Will C likes this
ratners
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 22, 2023

Hi Jared,

I know its been awhile - but a small hack that may help is included below.

Update the styleclass to include "sr-create-bound-issue":

<styleClass>sr-create-bound-issue issueaction-create-subtask</styleClass>

By including this class - you will activate the BehaviorContextId() which will hold the id of the button clicked to launch the form.

Create a Behavior which has mappings for all subtask types - or all issue types as it will only fire when the button is clicked.

In that behavior initializer you can catch the BehaviorContextId() as the first step - and if appropriate adjust the issuetype as shown below:

 

//If Behavior Context Id matches the WebItem ID for Subtask Creation
if (getBehaviourContextId() in ["add-artifact"]) {
//Set the Issue Type field to the ID of the subtask related to the button clicked (in this case 11001)
    getFieldByName("Issue Type").setFormValue("11001")
}

 

This design pattern should allow for alignment of issue type on Subtask Creation modal dialog - no full screen workaround needed!

 

Enjoy!

 

Seth

1 vote
Alina Fecheta
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 1, 2017

Hello,

You can create sub-tasks from the parent's screen by choosing More -> Create subtask

You can use the Behaviour plugin (part of Scriptrunner) to pre-populate it with values

 

Filip Håkansson February 1, 2017

Hello,

What our business requested is a specific button to create a sub-task of specific type.

Like "Create Approval Request" that brings up create sub-task screen with Issue Type set to "Approval Request"

Br

Filip

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events