Hello,
I use script runner to create subtask on transition, with additional issues actions like following :
1
2
|
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'GOL Issue Type'} |
I can't make it work.
'GOL Issue Type' is a select list field, with an option label "Foundation data Workbook
"
Can somebody help me to figure this out ?
Thanks
Select lists need an Option object as parameter for setCustomFieldValue(). Use this to find the value for setCustomFieldValue()
import com.atlassian.jira.component.ComponentAccessor // ... def fieldConfig = cf.getRelevantConfig(issue) value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Foundation data Workbook' }
Thanks a lot Henning ! The subtask is now well created but the customfield is not set to the value 'Foundation data Workbook' on the subtask.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Forget it, I didn't set the value :
issue.setCustomFieldValue(cf, value)
thanks :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great answer: Worked like a charm for me! Thanks, @Henning Tietgens
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All,
Currently it is not working when I create issue. No errors but the customfield is not set to the value.
Any thoughts why it may happen?
Scriptrunner Version:5.6.2.1-jira8
Jira Version: 8.1.1
But it perfectly works if i set this script to other transition post-function, for example from status 'OPEN' to status 'IN PROGRESS'.
I would appreciate any help!
My script:
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Department'}
def cfConfig = cf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == ' IM Department' }
issue.setCustomFieldValue(cf, value)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All,
I resolved my issue.
So I had to move my post-function to the 1st step before 'Creates the issue originally.'
After that it worked as expected.
This is because in my case script is fetching value from User Properties to apply it to custom field Select List (single choice).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, just adding my 2 cents to this post because I was struggling also.
I'm so newbie at this, I tried with the code in these posts, but ko.
Then I found this adaptavist KB from 2015 : https://www.adaptavist.com/doco/display/SFJ/Set+a+select+list+custom+field+value
(just a small mistake, he wrote "selectCf" instead of "cfSelect")
import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("My Custom Field name")
def cfConfig = cfSelect.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == 'The Value I want to set'
}
issue.setCustomFieldValue(cfSelect, value)
It works like a charm on Jira 8.8.1 + Scriptrunner 6.7.0 ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I didn't see any error when I run this script but the custom field is not updated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think this depends on the position of the custom field update. Currently I use this code to update custom fields:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def fieldLayoutManager = ComponentAccessor.fieldLayoutManager
issue.setCustomFieldValue(customField, newValue)
if (issue.id) {
def issueChangeHolder = new DefaultIssueChangeHolder()
def fieldLayout = fieldLayoutManager.getFieldLayout(issue)
def fieldLayoutItem = fieldLayout.getFieldLayoutItem(customField)
def modifiedFields = issue.getModifiedFields()
def modifiedValue = modifiedFields.get(customField.id)
customField.updateValue(fieldLayoutItem, issue, modifiedValue, issueChangeHolder)
}
If the issue id exists (that is after the issue was actually created), you have to use customField.updateValue().
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Henning Tietgens
The following script worked for me.
IssueService issueService = ComponentAccessor.getComponent(IssueService);
def optionsManager = ComponentAccessor.getComponent(OptionsManager);
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def issueObject = issueService.getIssue(user, issue.toString())?.issue
def customField = customFieldManager.getCustomFieldObjectByName("Release Onboarding Status")
Options options = optionsManager.getOptions(customField.getConfigurationSchemes().first().getOneAndOnlyConfig());
def selectedOptions = options.findAll {
it.value == "Not Requested"
}.collect {
it.optionId.toString()
}
// Setting none will work if it can't find an option
issueInputParameters.addCustomFieldValue(customField.id, *selectedOptions)
def update = issueService.validateUpdate(user, issue.id, issueInputParameters)
if (update.isValid()) {
issueService.update(user, update)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello - Is anyone else running into the default becoming permanent?
Both these scripts set the default, but then the field section can not be changes.
Example 1 - https://library.adaptavist.com/entity/set-a-default-option-on-a-select-list
Example 2- https://www.adaptavist.com/doco/sfj/how-to-articles/set-a-select-list-custom-field-value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you need to pass option object instead of string, check the following question
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.