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

This widget could not be displayed.

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
Posted 2 hours ago in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

9 views 0 0
Join discussion

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