Post function : Single select list custom field values setting on WF Transition

Maha vishnu v April 2, 2020

This is the below code i have used and had no working , Aggregate status is the field name , Design is the values want to set on transition Todo ==> inprogress 

Code 1 tried : 

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'MyCustomFieldType'}

issue.setCustomFieldValue(cf, 'Design')

compiled without error and its not working

Code 2 tried : 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
import com.atlassian.jira.issue.customfields.option.Option;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.MutableIssue;
MutableIssue currentissue = currentissue // Any one please explain what is mutable issue ? 
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Aggregate status'}
def fieldConfig = cf.getRelevantConfig(issue)
Option value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.value == 'Design' }
issue.setCustomFieldValue(cf, value)  

 

its not working and I need assistance from community  . 

 

Thanks and i appreciate your information . 

 

 

 

2 answers

1 accepted

2 votes
Answer accepted
Aditya Sastry
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.
April 2, 2020

@Maha vishnu v  Try this. I have tested it and it works. Accept the answer if you are happy so it can help others too.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

// the name of the custom field (single select list type)
final String customFieldName = "AIQ Detectability"

// the value of the new option to set
final String newValue = "Yes"

def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
//assert customField : "Could not find custom field with name $customFieldName"
def availableOptions = ComponentAccessor.optionsManager.getOptions(customField.getRelevantConfig(issue))
def optionToSet = availableOptions.find { it.value == newValue }

customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), optionToSet), new DefaultIssueChangeHolder())

Maha vishnu v April 2, 2020

@Aditya Sastry  , 

Its working and i'm happy with your answers . 

Can you please help me on this additional same functionality below with code alternatives  for Date field and multiple select list fields ? 

On transition i would like to defining Due date and Multiple select list field values  in place of ( select list field in above code  ) 

your answers could be more helpful . 

 

And Please correct my code in description , Where it was wrong and i would like to get  good approaches to learn script runner with groovy scripts ? Since I'm a beginner , this could be more helpful to get started .

Much Thanks !

Maha vishnu v April 5, 2020

@Aditya_Sastry, 

Do you have any information on my above appended request  ? 

If yes , It helps me a lot ! 

Harsh
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.
April 4, 2023

Hi can we do use the same JIRA 8.2? 
I am unable to do.

When user transit in Progress it should set customfield_xx (single select) value to 'ABC'.
Before In progress there is no value for the above custom field.

Any help will be appreciated.
Thanks!

0 votes
Aditya Sastry
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.
April 2, 2020

What plugins do you have? Let me know so I can help you with the changes.

Aditya Sastry
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.
April 2, 2020

try this -

issue.setFieldValue("Aggregate status",'Design')

Aditya Sastry
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.
April 2, 2020

did you try the above suggestion?

Maha vishnu v April 2, 2020

pic.png

Maha vishnu v April 2, 2020

Script Runner is the only plug-in in use 

Suggest an answer

Log in or Sign up to answer