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

Change value field list and checkbox field

I need Help!

I have 2 fields list (with the same content)

Address_current (in another issue - [Select List (single choice)]
Address_new (in the current issue - Database Information)

How do I update the address_current field with the address_new value using the runner script?


Another difficulty I'm having is the same situation (only with checkboxes)

Equipment_current (in another issue - checkboxes)
Equipment_new (in current issue - checkboxes)

How do I upgrade the Equipment_current field to the value of Equipment_new


I have a customfield with the ID and KEY of the issue I want to update

3 answers

1 accepted

0 votes
Answer accepted

Hello @Dante Labate

And welcome to Community :)

The thing is that you cannot just pass value in selectlist update, you need pass Option object to make it works, with checkboxes same situation.

Check article bellow:

https://community.atlassian.com/t5/Agile-articles/Three-ways-to-update-an-issue-in-Jira-Java-Api/ba-p/736585

There all info about correct updates fields.

Tks @Mark Markov

 

What am I missing?

The Address_new_value value is available in the Address Current

//address_new_value = "ABC, 34" (string)
//key_issue = RH-123

def String myval2 = "${address_new_value}"
def issue2 = issueManager.getIssueObject("${key_issue}")
def customFieldManager2 = ComponentAccessor.getCustomFieldManager()
def cfSelect = customFieldManager2.getCustomFieldObjects(issue2).find {it.name == "Address Current"}
def cfConfig = cfSelect.getRelevantConfig(issue2)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == "${myval2}"
}
issue2.setCustomFieldValue(cfSelect, value)

 

This will run in a post function

 

Mark Markov Community Leader Jun 18, 2018

Youre missing 

// apply changes to Jira -----------------------
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

to apply changes 

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption


def customFieldManager = ComponentAccessor.getCustomFieldManager()

def id_contratacao = customFieldManager.getCustomFieldObject("customfield_16056")
def key_value = issue.getCustomFieldValue(id_contratacao).toString()

def endereco_proposto = customFieldManager.getCustomFieldObject("customfield_15707")
def endereco_proposto_valor = issue.getCustomFieldValue(endereco_proposto).toString()

IssueManager im = ComponentAccessor.getIssueManager();
MutableIssue issue = im.getIssueObject(key_value) as MutableIssue;

def String myval2 = "${endereco_proposto_valor}"
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Endereço")
def cfConfig = cfSelect.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == "${myval2}"
}
issue.setCustomFieldValue(cfSelect, value)

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

 

The script runs successfully, but when I look at the other problem, it did not update the list field.

Mark Markov Community Leader Jun 18, 2018

value must get like this

def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.value == "${myval2}"
}

I made this change, but it still is not working.

:(

I figured out what was not letting it work.

for some reason (I can not say) the script runner was not recognizing the field name so I changed to id and it worked.

before:
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName ("Address")

after:
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObject ("customfield_13421")

 

TKS @Mark Markov

I already did something similar, but the destination field was text

 

def issueService2 = ComponentAccessor.getIssueManager() 
def issue2 = issueManager.getIssueObject("${KEY_ISSUE}")
def String myval2 = "${address_new_value}"
def customFieldManager2 = ComponentAccessor.getCustomFieldManager()
def textCf2 = customFieldManager2.getCustomFieldObjects(issue2).find {it.name == "Address_current"}
if (textCf2) {
def changeHolder = new DefaultIssueChangeHolder()
textCf2.updateValue(null, issue2, new ModifiedValue(issue.getCustomFieldValue(textCf2), myval2),changeHolder)
}

But it does not work.

Could someone help me with correct script for this situation?

@Mark Markov

 

I tried to use the same list method to checkbox and it did not work.
(the script does not return error, but does not change the destination field)

Just to remember what I want.

I have two field checkboxes:
Equipment_current (in other problem - checkboxes)
Equipment_new (in current issue - checkboxes)

How do I update the Equipment_current field to the value of Equipment_new in a post function.

 

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def id_contratacao = customFieldManager.getCustomFieldObject("customfield_16056")
def key_value = issue.getCustomFieldValue(id_contratacao).toString()

def equipamento_proposto = customFieldManager.getCustomFieldObject("customfield_15721")
def Equipment_new_value = issue.getCustomFieldValue(equipamento_proposto).toString()

//IssueManager im = ComponentAccessor.getIssueManager();
//MutableIssue issue = im.getIssueObject(key_value) as MutableIssue;

def String myval2 = "${Equipment_new_value}"
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_15720") //tipo de equipamento atual
def cfConfig = cfSelect.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find
{it.toString() == "${myval2}"}
issue.setCustomFieldValue(cfSelect, value)

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED,

I'm testing the change first in the same issue, then I'll edit the field in the other issue.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

851 views 7 0
Join discussion

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