Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Change value field list and checkbox field

Dante Labate June 18, 2018

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
Mark Markov
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.
June 18, 2018

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.

Dante Labate June 18, 2018

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
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.
June 18, 2018

Youre missing 

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

to apply changes 

Dante Labate June 18, 2018
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
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.
June 18, 2018

value must get like this

def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.value == "${myval2}"
}
Dante Labate June 18, 2018

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

:(

Dante Labate June 18, 2018

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

0 votes
Dante Labate June 19, 2018

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

0 votes
Dante Labate June 18, 2018

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?

Suggest an answer

Log in or Sign up to answer