Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Behaviours is showing compilation error with scriptrunner -4.3.15

Rashmi Belur September 18, 2017

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

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Joshua Yamdogo @ 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.
September 18, 2017

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)
TAGS
AUG Leaders

Atlassian Community Events