Hi, Everyone!
Guys, i try to solve my business case with groovy script listener but seems my attempts do not rich up the result.
What i have:
issue type named "SoW"
Field (Checkbox) named "Last Iteration" with value "Yes"
Link Name: "SoW iterations"; Inward Description: "is Next iteration of"; Outward Description "is Previous iteration of"
Case:
The field "Last Iteration" should be unchecked (cleared) in all (inward) linked issues when updating this field in the issue without outward links (is Previous iteration of)...
There is my script (A kind of similarity),
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
def issueLinkManager = ComponentAccessor.getComponent(IssueLinkManager)
if issue.issueTypeObject.name == 'SoW' && issueLinkManager.getOutwardLinks(issue.getId()).any {
it.issueLinkType.name == "SoW iterations"
}
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Last iteration'}
issue.setCustomFieldValue(cf, null)
}
Hope you help,
Guys, now its work fine. Solved by myself, maybe useful to someone else:
//import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
issueLinkManager.getOutwardLinks(issue.id).each { issueLink ->
if (issueLink.issueLinkType.name == "SoW iterations") {
System.err.println("links: " + issueLink.issueLinkType.name.toString())
def linkedIssue = issueLink.destinationObject
System.err.println("issue: " + issueLink.destinationObject.toString())
// Update "Last Iteration" field;
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfLA = customFieldManager.getCustomFieldObjectByName("Last iteration")
def fieldConfig = cfLA.getRelevantConfig(linkedIssue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Yes", null)
def cfLAvalue = linkedIssue.getCustomFieldValue(cfLA)
System.err.println("old value: " + linkedIssue + linkedIssue.getCustomFieldValue(cfLA))
if (cfLA) {
def changeHolder = new DefaultIssueChangeHolder()
cfLA.updateValue(null, linkedIssue, new ModifiedValue(cfLAvalue, [option]), changeHolder)
//inkedIssue.setCustomFieldValue(cfLA, option)
System.err.println("new value: " + linkedIssue + linkedIssue.getCustomFieldValue(cfLA))
}
}
}
true
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One more iteration of my script is present on a bottom. Now i try to solve behavior of my custom field: it is not updated in JIRA, but log says the value was updated. Maybe i miss something?
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.link.IssueLink
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "SoW iterations") {
System.err.println("links: " + issueLink.issueLinkType.name.toString())
def linkedIssue = issueLink.destinationObject
System.err.println("issue: " + issueLink.destinationObject.toString())
// Update "Last Iteration" field;
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfLA = customFieldManager.getCustomFieldObjectByName("Last iteration")
def fieldConfig = cfLA.getRelevantConfig(linkedIssue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Yes", null)
def cfLAvalue = linkedIssue.getCustomFieldValue(cfLA)
System.err.println("old value: " + linkedIssue + linkedIssue.getCustomFieldValue(cfLA))
if (cfLA) {
linkedIssue.setCustomFieldValue(cfLA, "Yes")
System.err.println("new value: " + linkedIssue + linkedIssue.getCustomFieldValue(cfLA))
}
}
}
Log:
links: SoW iterations
issue: ZONTVCABO-119
old value: ZONTVCABO-119null
new value: ZONTVCABO-119Yes
Please help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am trying to set a customfield value for a date field in the linked ticket as below
IssueLinkManager linkManager = ComponentAccessor.getIssueLinkManager();
List<IssueLink> issueLinks = linkManager.getOutwardLinks(issue.getId());
for(IssueLink link : issueLinks) {
log.debug("link name " +link.getDestinationObject().getStatus().getName())
if (link.getIssueLinkType().getName().equals("XXX)")){
Issue duplicateTicket = link.getDestinationObject();
duplicateTicket.setCustomFieldValue(plannedregDate,issue.getCustomFieldValue(plannedrcdate))
Is there anything wrong I am doing. Can you please help
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.
Guys, your assistance still required in this case.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Guys, I have modified my script, it helps solve errors from the log file, but seems still not working, here my new script:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.MutableIssue
MutableIssue issue = issue
import com.atlassian.jira.issue.link.IssueLink
def componentManager = ComponentManager.getInstance()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getOutwardLinks(issue.id).findAll {
it.issueLinkType.name == "SoW iterations"
}.each {
// Update "Last Iteration" field;
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfLA = customFieldManager.getCustomFieldObjectByName("Last iteration")
def fieldConfig = cfLA.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Yes", null)
issue.setCustomFieldValue(cfLA, [null])
}
Hope you help,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
YES
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.