Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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
Community showcase
Published in Confluence Cloud

🎨 Add some visual life to your templates

Hi Atlassian Community, My name is Avni Barman, and I am a Product Manager on the Confluence Cloud team. Based on feedback from you, we are giving admins more power to create templates that a...

63 views 1 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you