Behaviours is showing compilation error with scriptrunner -4.3.15

I am using Scriptrunner 4.3.15. Trying the Behaviours for first time and as per the example- https://scriptrunner.adaptavist.com/4.3.15/jira/recipes/behaviours/subtask-default-fields.html

I am trying to set component for Sub Task & getting below error

Compilation failure: startup failed: Script1.groovy: 3: unexpected token: package @ line 3, column 1. package com.onresolve.jira.groovy.test.behaviours.scripts ^ 1 error

 

My script is as below  Please suggest. I am using server side script

 

 

package com.onresolve.jira.groovy.test.behaviours.scripts

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.customfields.option.Option

import com.atlassian.jira.issue.fields.CustomField

import com.onresolve.jira.groovy.user.FieldBehaviours

import com.onresolve.jira.groovy.user.FormField

import groovy.transform.BaseScript

import java.sql.Timestamp

import static com.atlassian.jira.issue.IssueFieldConstants.*

 

@BaseScript FieldBehaviours fieldBehaviours

 

FormField field = getFieldById(getFieldChanged())

FormField parent = getFieldById("parentIssueId")

Long parentIssueId = parent.getFormValue() as Long

 

if (!parentIssueId || field.getFormValue()) {

    // this is not a subtask, or the field already has data

    return

}

 

def issueManager = ComponentAccessor.getIssueManager()

def parentIssue = issueManager.getIssueObject(parentIssueId)

def customFieldManager = ComponentAccessor.getCustomFieldManager()

 

// REMOVE OR MODIFY THE SETTING OF THESE FIELDS AS NECESSARY

 

getFieldById(COMPONENTS).setFormValue(parentIssue.components*.id)

1 answer

1 accepted

1 vote
Answer accepted

Hi Rashmi,

All you need to do is remove the first line of code. The package name is not necessary and will cause an error.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import java.sql.Timestamp
import static com.atlassian.jira.issue.IssueFieldConstants.*

@BaseScript FieldBehaviours fieldBehaviours

FormField field = getFieldById(getFieldChanged())
FormField parent = getFieldById("parentIssueId")
Long parentIssueId = parent.getFormValue() as Long

if (!parentIssueId || field.getFormValue()) {
// this is not a subtask, or the field already has data
 return
}

def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issueManager.getIssueObject(parentIssueId)
def customFieldManager = ComponentAccessor.getCustomFieldManager()

// REMOVE OR MODIFY THE SETTING OF THESE FIELDS AS NECESSARY

getFieldById(COMPONENTS).setFormValue(parentIssue.components*.id)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Thursday in Jira

Updates to jira.atlassian.com give you visibility into what's coming in Jira Server and Data Center

Hello, Community! My name is Gosia and I'm a Product Manager on Jira Server and Data Center here at Atlassian. Since 2002 when we launched our public issue tracker, jira.atlass...

327 views 1 12
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