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

Explanation about SubTasks Defaults fields

Maille Christine June 7, 2017

In the Script runner documentation sample for SubTasks Defaults fields, it is written:

"This script hinges on the parentIssueId being present in the form. As such, you will need to associate the script with a visible field. It will not work as an initialiser. "

 

I don't understand what I have to do to make it running? how can associate the script to a visible field?

 

Please help me on this point.

 

Thank you in advance

 

C.Maille

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Stephen Cheesley _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.
June 8, 2017

Hi Maille,

What this is explaining is that BECAUSE you need the parentIssueId, you CANNOT use the script in the initialiser. What this means is that you must use the script in ANY VISIBLE FIELD in the issue, in order for it to have access to the resources it needs to work.

Example:

1. I created a custom text field called "Tech Lead" for a given issue. This field just contains some text (a name).

2. If you take a look in behaviours and select the "Fields" operation for your desired behavior:

Fields.PNG

3. At this point, add a field to the beviour (NOTE: You can add ANY visible field and this should work, for the demo I am using my custom field)

add_field.PNG4. Once you have added your field you just then need to add your script to the field as shown here:

add_script.PNG

That's it! Once your script is in, it should just work.

Note: 
You need to edit the script in order to get it to migrate the values you want. Just reply if you need any help with that part :-)

Thanks,

Steve

Maille Christine June 8, 2017

Thank you very much for your quick answer. I tried to copy the script given as sample ; now I have an error in the script...

here is the begining of the script I tried to use and I got an error at the line import "unexpected token"

can you help me again? thank you in advance...

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

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

@BaseScript FieldBehaviours fieldBehaviours

FormField field = getFieldById(getFieldChanged())

...

Maille Christine June 8, 2017

Thank you very much for your quick answer. I tried to copy the script given as sample ; now I have an error in the script...

here is the begining of the script I tried to use and I got an error at the line import "unexpected token"

can you help me again? thank you in advance...

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

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

 

..."

Stephen Cheesley _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.
June 8, 2017

Hi Maille,

It is a typo in the script example. You just need to make sure import and static are on the same line.

Also I've just noticed, if you are putting it directly into the script editor, you don't need the "package" line either :-)

Thanks,

Steve

Maille Christine June 8, 2017

in fact I found that behind the import... we had some lines. If I add those lines it works better but not fully.

I have set the script for the field Summary and reduce it to have only 2 fields prefilled: Summary and Assignee, only the Summary is populated with the value of the Parent...

Do I miss something? or?...

here is the script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.web.util.OutlookDate
import com.atlassian.jira.web.util.OutlookDateManager
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(SUMMARY).setFormValue(parentIssue.summary)
getFieldById(ASSIGNEE).setFormValue(parentIssue.assigneeId)

Stephen Cheesley _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.
June 8, 2017

Hi Maille,

I created a basic Behaviour with the script that you gave me. I created a parent task with the summary and assigned user values populated. I then created a sub task and the summary and the assignee fields are both populated with the values from the parent. It looks as though your script works!

Could you send me a screenshot of your behaviour setup?

Thanks,

Steve

 

Maille Christine June 8, 2017

$44D78BBFFF93319B.jpg

Stephen Cheesley _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.
June 8, 2017

Can I ask, what versions of JIRA and ScriptRunner do you have?

Maille Christine June 8, 2017

Yes sure:

JIRA Software 7.1.10

JIRA Core 7.1.9

Scriptrunner 4.3.6

 

I know that some new versions exist but I'm not the one who decide to take a new version...

I hope it will help

Christine

 

Stephen Cheesley _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.
June 8, 2017

Does it work if you swap out description for assignee?

Maille Christine June 8, 2017

Yes it works for summary and description... a problem with the Field Type? or the syntaxe?

Stephen Cheesley _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.
June 8, 2017

Ok, I believe that this is an issue with the assignee field. There were bugs in earlier versions of the scriptrunner behaviours plugin around setting values on the assignee.

I would recommend that you update your plugin to the latest version. You'll get all the latest bugfixes and features, which will fix this issue.

Maille Christine June 8, 2017

I'm not the decider there...

Maille Christine June 9, 2017

one more point: I wil check when I can install the new version...

waiting for this do you have a list about the fields where it works and the fields where we can have potential problems.

It will be very helpfull for me...

Anyway thank you very much for your help on this topic.

 

TAGS
AUG Leaders

Atlassian Community Events