Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set default custom field when issue moved to one project to another project

siva
Contributor
February 2, 2022

Hello,

In my jira instance we had a custom field called "Super Power" (user picker type)this field already set to default value 'SIVA' by using custom field configure. But here the issue is when issue is moved to project A to project B the custom field also reflects the same value 'SIVA' but i need a different value 'RAJA' in project B.

I wrote a script using scriptrunner behaviour 

 

import com.atlassian.jira.component.ComponentAccessor

def FieldName = getFieldByName("<Super Power>")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(FieldName.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionToSelect = options.find { it.value == "<RAJA>" }
FieldName.setFormValue(optionToSelect.optionId)

And finally mapped the issuetype and project B to behaviour. But the above script not working can any one please help me how to solve this issue.

Thanks,

Siva.

2 answers

0 votes
Sachin Dhamale
Community Champion
February 2, 2022

@siva - You need to write groovy script to update the custom field on the script listener for move issue events. The behavior script is not going to work. see the screenshot

Pls Accept the answer if you find this helpful. Let me know if you have any queries

 

Custom Listner.png

 

 

siva
Contributor
February 2, 2022

@Sachin Dhamale 

Thanks for the reply and i tried in  script listener and it shows so many errors in this code can please help with code how to update custom field (PM Lead) when issue moved from one project to another project

error code_LI.jpg

Thanks,

Siva

Sachin Dhamale
Community Champion
February 3, 2022

@siva  - You need to write groovy script instead of behavior script. You can refer bellow.

instead of current user you can get the object of user which you want to update.

Please Accepts the answer if you find helpful

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def customFieldManager = ComponentAccessor.getCustomFieldManager()

// a user custom field
def userCf = customFieldManager.getCustomFieldObjectByName("User Picker Customfield Name")
def currenrUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setCustomFieldValue(userCf, currenrUser)
ComponentAccessor.getIssueManager().updateIssue(currenrUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
siva
Contributor
February 4, 2022

@Sachin Dhamale 

The script you sent showing few errors here the screen shot below

code error.png

can you please help me with script i'm new to script runner and your help much appreciated.

Thanks,

Siva.

0 votes
Rilwan Ahmed
Community Champion
February 2, 2022

When is the script running ?

siva
Contributor
February 2, 2022

@Rilwan Ahmed 

Thanks for the reply but i didn't get you what you are asking can you please elaborate little bit.

Thanks,

Siva 

Rilwan Ahmed
Community Champion
February 2, 2022

when are you calling the script to be executed ?

siva
Contributor
February 2, 2022

When issue moving one project to another project.

Thanks,

Siva

Suggest an answer

Log in or Sign up to answer