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
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:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Youre missing
// apply changes to Jira -----------------------
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
to apply changes
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
value must get like this
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.value == "${myval2}"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.