Explanation about SubTasks Defaults fields

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

This widget could not be displayed.

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

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())

...

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.*

 

..."

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

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)

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

 

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

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

 

Does it work if you swap out description for assignee?

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

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.

I'm not the decider there...

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.

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

168 views 1 3
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