Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with ScriptRunner Behaviours since May release

Yoann LEGRAND
Contributor
May 23, 2018

Hello, 

We have a behaviour to add a message when we create a Subtask ( check if subtask type is compatible with parent issue) , just like this : 
SST.png

 

Since new release ( 5.4.1 ) this behaviour is not working anymore  ( OK with release 5.2.2).

 

Option of this behaviour : 

  - Mapping all Projet / All issue types
  - Behaviour settings : 
     - No use validator plugin
     - Guide Workflow : None
     - No Initialiser
 - Fields : 
     - Issue Type :
          - Optional
          - Writable
          - Shown
        - No condition


  script : 

 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE

@BaseScript FieldBehaviours fieldBehaviours

FormField formIssueType = getFieldById(getFieldChanged())
FormField formParentIssueId = getFieldById("parentIssueId")
Long parentIssueId = formParentIssueId.getValue() as Long

if (!parentIssueId) {
// this is not a subtask
return
}

def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issueManager.getIssueObject(parentIssueId)
def parentIssueTypeName = parentIssue.getIssueType().name
def constantsManager = ComponentAccessor.getConstantsManager()

if (parentIssueTypeName == "Project" || parentIssueTypeName == "Epic" || parentIssueTypeName == "Target" ) {
formIssueType.setHelpText("It is not allowed to create subtasks in Epic or Project or Target")
return
}

if (parentIssue.status.name == "Closed" ) {
formIssueType.setHelpText("It is not allowed to create subtasks when the parent is closed")
return
}

//add subtasks allowed on all tickets
List allowedSubtasks = constantsManager.getAllIssueTypeObjects().findAll {
it.name in ["Communicate - Escalate","Conduct Meeting","Document","Report","Sub-Task"]
}.collect {
it.id
}

if (parentIssueTypeName == "Incident") {
allowedSubtasks.addAll(constantsManager.getAllIssueTypeObjects().findAll {
it.name in ["Deploy","Validate and Execute Test","Fix"]
}.collect {
it.id
})
}

// Too many condition ....

else if (parentIssueTypeName == "Service Request") {
allowedSubtasks.addAll(constantsManager.getAllIssueTypeObjects().findAll {
it.name in ["Deploy"]
}.collect {
it.id
})
}

if (allowedSubtasks.contains(formIssueType.getValue())) {
formIssueType.clearHelpText()
} else {
formIssueType.setHelpText("This is not a valid subtask type for issue type " + parentIssueTypeName +

".")
}

 

1 answer

1 accepted

1 vote
Answer accepted
Thanos Batagiannis [Adaptavist]
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 23, 2018

Hi Yoann, 

We are aware of this bug and there is actually a dev issue SRJIRA-2738, please vote for it and start watching it in order to get updates regarding its status.

Apologies for any inconvenience this may caused,

Thanos

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events