Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Can you help with behaviour on service desk to populate fields on form using existing issue

We create an issue using a recruitment request on the Service desk. This issue contains data such as job title, start date, office, business unit, etc.

I would like to populate the same fields in our Onboarding request in the Service Desk using the information already entered on the recruitment request.

I have created an Issue Picker scripted field to allow the user to select the correct recruitment request. 

I have been advised I need to use the behaviours getValue() method with the issueManager.getIssueByCurrentKey("issuekey") method to get the issue object. But I just don't know how to structure up the script to achieve it.

Can someone provide a sample of how this would be achieved. Please include all imports and definitions as well.

2 answers

2 accepted

0 votes
Answer accepted

Hi Nicole

If you want to get the values of the fields from an issue that the user has selected in a scriptrunner Issue Picker scripted field, you can use a behaviour script like this example here.

My example gets the selected issue that the user chooses, finds a Text field named TesxtFieldA and gets that fields value from the selected issue. Then it sets the value of the TextFieldA field on the current Create Request screen.

i.e. pulls in value from another issue and sets the current forms field value to the same.

it also sets the description on the TextFieldA field to tell the user that the value of the field has been set from another issue.

I hope this helps




Thanks Matthew, 

That has me well on my way.

I get the expected response in the log thanks to the debug you added.

custom Text Field = [Database Developer (HS-16542)]
summary = Database Developer

Related issue values:

Selected Issue Summary = Database Developer
Selected Issue Key = CORP-14114
value type = class java.lang.String
value = CORP-14114
value type = class java.lang.String
value = null

I get the key included in the default message under each field.

"Defaulted value set from related issue CORP-14114"

I haven't gotten any of the fields to populate yet. Do I have to do something differently for date fields or if I want to populate Insight Custom fields?

In your script I have replaced "TextFieldA" with the field name "Job Title" - { == "Job Title"} & getFieldByName("Job Title").  Is there any other part of your script where I should be making replacements, defining fields, or doing other things developers just know how to do?

Hi Nicole

Dates are a little different as you need to set the correct format that the form field expects.

I have written a method that can be used to set date fields from behaviours.

Have a look at this new version of the script here.

The insight custom fields might be more complicated as I do not really know what input format they require or even if they can be set from behaviours.

I would need to know what type of insight field the field is and how I can set up the same field in order to help with populating it from behaviours.


Try logging out the values of the insight fields in the behaviour when a user selects values so you can see what the data looks like. i.e. what the value is and also its data type




Hi Matthew,

Starting wearing your underpants on the outside as you are officially a superhero! :)

According to the community, Insight fields aren't supported in Behaviours just yet, but I have voted on the request SRJIRA-2563

I have switched back to regular custom fields as Insight is still in evaluation phase, so your efforts won't go to waste.

Have a fantastic day.

Like Matthew Clark likes this

Hi again Matthew,

Some of the fields on the issue I have selected using my issue picker come from a Select List (single choice).  I can't get them to default populate the same fields on my portal.  Could you provide an example for this type of field please.

Dates and Text fields are working great.

Hi Nicole

Apologies for the delay, it has been very busy recently so I have not been able to respond as quick on the community.

You can set "single select list" fields with values obtained from another issues "single select list" field as I show in this example here.

Please test it first as I had to write and test it fairly quickly.



Thanks Matthew.  I will test shortly. I have been on hiatus like many others.  I'm sure this will help tremendously.

0 votes
Answer accepted
Will C Rising Star Feb 17, 2020

I think the best way ro do this would be through a workflow post function on the first issue, which then kicks off the creation of the second issue.

do you need to copy all fields from the first issue to the second one? if so then using a clone method would be best, otherwise you need to get values of fields one by one and then set it on the second issue.

we would need to set the issuetype and/or the project on the second issue so that it follows the different workflow.

Does this sound like the sort of thing that you are after?

Thanks Will,

I had built the solution the way you described, but unfortunately this does not work for our particular scenario.  The second issue needs to be created in the Service Desk portal so that users don't have to have a service desk licence to complete the extra fields that are required on the second request. 

On the service desk portal, I want users to specify the issuekey of the first request, then have the Behaviours populate the same values for those fields that are also in the second request. These values will be defaulted, but can be updated if needed. For example, if the start date changes. Then the user would complete the second request with the new information such as First Name, Last Name, now that we know who we have hired. 

Will C Rising Star Feb 18, 2020

Hi Nicola,

Can you tell me why it wouldn't work in the post function?

Even if the user didn't have the rights to create an issue in another project, somebody from your team could make the transition and this would kick off the script to create it, you can instantiate another user in the script who can be the creator of the issue.

if you want to do it the behaviour way, please note this script is not the finished article but is pretty much there, you will need to alter various formats to set the fields dependant on what they are.


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FormField
@BaseScript FieldBehaviours fieldBehaviours

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()

def currentIssue = underlyingIssue // get issue you are on

def issueToCopyFrom = issueManager.getIssueObject("Test-1") // get issue to copy from

def cf1 = customFieldManager.getCustomFieldObjectsByName("test1")[0] // get custom fields
def cf2 = customFieldManager.getCustomFieldObjectsByName("test2")[0]
def cf3 = customFieldManager.getCustomFieldObjectsByName("test3")[0]

def cf1v = issueToCopyFrom.getCustomFieldValue(cf1) // get custom field values on issue to copy from
def cf2v = issueToCopyFrom.getCustomFieldValue(cf2)
def cf3v = issueToCopyFrom.getCustomFieldValue(cf3)

def cf1vForm = getFieldByName("test1") //get form field using behaviour
cf1vForm.setFormValue(cf1v) // set form field, might need to use cf1v.toString() depending on the custom field type

def cf2vForm = getFieldByName("test2")

def cf3vForm = getFieldByName("test3")

Hi Will,

We already have lots of other automation and behaviours in place in both the portal form and postfunctions already. So it's not that your suggestion wouldn't work. It would however, require us to change the business process and involve others that are not currently involved. We want to have the tool support the process, not change the process to support the tool.  The recruitment (first) issue has around 7 fields, while the onboarding (second issue) has over 20, which appear and disappear based on other selections during the process. I am just trying to reduce the fields that need to be entered during onboarding since we already entered that data in the recruitment.

The team at Scriptrunner have pointed me in the right direction, by advising I can achieve the outcome I want if I use the behaviours getValue() method with the issueManager.getIssueByCurrentKey("issuekey") method to get the issue object to default the values from the issuekey of the first issue into the second key while still in the Service Desk portal. 

I just don't have the skillset to execute on it, hence my post here. Once I get an example for one field, I can follow the pattern for the rest. 

Thanks for responding. It is much appreciated. I may use your example for something else.

Will C Rising Star Feb 19, 2020

Hi, the code I wrote will achieve what you are after by using the Behaviours method.

All that is missing is getting the custom field value and then using the issueManager.getIssueObject("") call using the value of that.

Hi Will,

I have tried, but without the bits that's missing (All that is missing is getting the custom field value and then using the issueManager.getIssueObject("") call using the value of that.) I am not having any success.

Would you mind scripting getting value of one field from an existing issue for me.

I have created the Issue Picker scripted field that allows the user to select the required issue from which to extract values.  If you assume this issue has a field called Title. How would you write the script to extract and use that to populate the same field on the new issue?  

Hi Nicola,

this code will be able to get the issue from an issue picker using issuemanager:


def issueFromCFV = customFieldManager.getCustomFieldObjectsByName("Test Issue Picker")[0]
def issueFromCFVV = currentIssue.getCustomFieldValue(issueFromCFV)

def issueToCopyFrom = issueManager.getIssueObject(issueFromCFVV.toString())

This will get the value from an issue that already has the issuepicker saved to it, if you want to get it using a behaviour and watching for changes on the form that will need to be done in a different way. 

Hi Will,

Seems my insight custom fields were getting in the way.  Thanks so much for trying. It is much appreciated. 

Matthew at Scriptrunner has included a link to a nice clean script that gets text fields and date fields in this thread.

Hi Matthew,

The log shows it is picking up the correct value, but it is not populating on the screen.

selectList value = FINANCE
Type of selectList value = class com.atlassian.jira.issue.customfields.option.LazyLoadedOption

The field I am testing has many context configurations based on project and issue types. Could that be affecting the result. I get the same result testing several different fields. Also I added your latest update to the existing script, should it be run standalone first? Any advice?

Also what do I use to populate a user picker field?

I registered your initial script for text and date type fields, and it is now available in the library for everyone else to benefit from your knowledge - :)

Hi Nicole

Apologies for the late reply, it has been non-stop busy for a while now so my community responses have slowed down.

This thread has become a little confusing and I am not sure what problem we are at now so maybe if you still need help it would be better to open a new question or start a new thread on here.



All good.  Got the last bit from the Adaptavist Library snippets.  :)

Thanks for all your help, couldn't have done it without you.

Like Matthew Clark likes this

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events