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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published yesterday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

446 views 6 7
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