Default Subtask issue type using behavior

I've created a Script fragment to create a subtask, Please see below xml similar to the one mentioned here(https://community.atlassian.com/t5/Product-Apps-questions/Scriptrunner-web-fragments-for-creating-subtask-with-default/qaq-p/55927)

 <web-item key='createFeed' name='ScriptRunner generated web item - createFeed' section='operations-top-level' weight='1'>
   <label>Feed</label>
    <condition class='script:jiraHelper.project?.key == "ABC"&amp;issue.issueType.name == "Story"'/>
    <styleClass>issueaction-create-subtask</styleClass>
     <link linkId='createFeed'>/jira/secure/CreateSubTaskIssue.jspa?parentIssueId=${issue.id}&amp;pid=${issue.projectObject.id}&amp;issuetype=11111</link>
   </web-item>

Error: I have 2 subtasks types, because of jira's default behavior the issue type is selected to the latest subtask issue type created.

Steps taken to solve the error: I tried using the Behaviours integration to set the issue type to default, Please see below script as mentioned in the documentation:https://scriptrunner.adaptavist.com/4.1.3.24/jira/fragments/CreateConstrainedIssue.html#_behaviours_integration

    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.issue.IssueManager;

    def issueManager = ComponentAccessor.getIssueManager()
    if (getBehaviourContextId() == "createFeed") {       getFieldById("issuetype-field").setReadOnly(true)
    }

But this doesn't work. Am I missing anything or is this because of the styleClass I've used. issueaction-create-subtask

I need the subtask screen to popup when the script fragment button is clicked, with the issue type field set as read only.

Pleas advise. Thanks.

1 answer

0 vote
Alexey Matveev Community Champion Nov 02, 2017

Hello, 

In the following line

getFieldById("issuetype-field").setReadOnly(true)

 What do you use for issuetyle-field? It must be like customfield_<id>. If you use the name of the custom field you need to call getFieldByName method. 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

82 views 0 5
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