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
4,368,548
Community Members
 
Community Events
168
Community Groups

Listener Clone ticket is not updating a CF after creation

Edited

Hi,

I am trying to use lister to clone a ticket when the original ticket is resolved and update the ticket cloned ticket with CF x to CF Y

My current settings are:

condition: 

cfValues['Request Type']?.value == 'X'

Additional issue actions:

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.ModifiedValue

 

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Request Type")

issue.setCustomFieldValue(cf,'Y')

issue.setAssignee(null)

I also tried: 


def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Request Type'}
issue.setCustomFieldValue(cf,'Y')
issue.setAssignee(null)


so the ticket is cloned and the relevant fields are copied but the request type is X and not being modified to Y. It is not even showing up on the cloned ticket so I believe the value is being 'null'...
any idea what I am doing wrong?
thanks,

1 answer

0 votes
fjodors Rising Star Oct 19, 2018

Hi

If you are trying to update custom field from listener you should use mutableIssue .

Here is an example how to update issue custom field from script runner listener: https://community.atlassian.com/t5/Jira-questions/Changing-custom-field-in-Listener-not-re-indexing-issue/qaq-p/902472#M289567

Thanks Fydor - ill test and let you know the results...

 

FYI - the listener already have an examples built in, this is where I took the code for: 

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Request Type")

issue.setCustomFieldValue(cf,'Y')

and I tested by changing the summary to include the new value using:

issue.summary = "Request Type value is: " issue.getCustomFieldValue(cf)

and the summary of the new issue shows "remove" - the only thing that doesn't actually get updated is the custom field value.... so weird...

Unfortunately it did not work

I can clone all the relevant fields into the new ticket (needs less fields from the original one), but this specific field for the request type is not getting updated.

I also tried to index, but nothing helps

might be my groovey version (5.0.11) or my Jira (7.3.4)

But I cannot accept the answer as the field has not updated

I also tried to set the assignee - and it works only if assignee in null:

issue.setAssignee(null)

but 

issue.setAssignee(UserManager.getUserByName("{usr_name}")) did not work

fjodors Rising Star Oct 26, 2018

Hello

Hmm, this is strange.
Probably it is related with custom field type (string, number, select option...)- for.e.g you are trying to update number custom field with string value?
I recommend you to check your Jira version API, probably there are some changes in methods and classes - https://docs.atlassian.com/software/jira/docs/api/7.3.4/index.html?overview-summary.html
Also try to enable logging in your listener and check output:
....
import org.apache.log4j.Category
...
log.setLevel(org.apache.log4j.Level.<your level>)
log.info("start logging...");
....

you are correct, i'm trying to change a custom field that is a drop down and not just a text field.... maybe to do that i need the id of the value instead of the text...

will have to search the API  - unless you have some quick example for me...

thanks,

You need to get specific option and set it to your custom field.

Try something like this. 



//issueToUpdate - your target issue
def CF=customFieldManager.getCustomFieldObjectByName('Select_list');
def fieldConfig = CF.getRelevantConfig(issueToUpdate)
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
def optionA = optionsManager.getOptions(fieldConfig).find {it.value == "OptionA"}
issueToUpdate.setCustomFieldValue(CF, optionA);
issueManager.updateIssue(event.getUser(), issueToUpdate, EventDispatchOption.ISSUE_UPDATED, false);

 

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events