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

Listener Clone ticket is not updating a CF after creation

Ronen Erlich October 17, 2018

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

Suggest an answer

Log in or Sign up to answer
0 votes
fjodors
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.
October 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

Ronen Erlich October 19, 2018

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...

Ronen Erlich October 25, 2018

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

Ronen Erlich October 25, 2018

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
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.
October 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...");
....

Ronen Erlich October 26, 2018

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,

fjodors
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.
October 29, 2018

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);

 

TAGS
AUG Leaders

Atlassian Community Events