Hi Community,
I am using ScriptRunner for the first time, have no previous programming experience and am working on using the function "Clones an Issue, and links". I added the function as a post function in the workflow when a defined status was reached.
The issue should be cloned into the second project, in addition a link to the source issue and a comment added with a defined text and by who the action was triggered.
These actions also work, but I am attached to the problem that if the issue has already been cloned once, a status change of the issue will clone it a second time. But if it has already been cloned once, it cannot be cloned a second time. I want to avoid duplicate clones.
For this I have created a CustomField, which I read out in the condition and, if necessary, set in the Additional issue action. I am stuck here and hope for your support.
I have already searched through some documentation, but have not yet come up with the right result.
Any idea what is wrong here?
On the screenshot you can see that whenever the ticket is opened and closed again, a clone is created several times and the custom field is not changed.
The code is as following:
Condition:
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
//cfValues['Clone']?.value != "Yes"
//cfValues['Clone']*.value.contains("Yes")
if (cfValues['Clone']*.value.contains("Yes")) {
return false
} else {
return true
}
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
! changeHistoryManager.getAllChangeItems(issue).find {
it.field == "Done"
}
Additional issue actions:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfig
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Clone")
def fieldConfig = cf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Yes' }
issue.setCustomFieldValue(cf, [value])
//def cf = customFieldManager.getCustomFieldObjectsByName("Clone") // Checkboxes is the NAME of my custom field
//def fieldConfig = cf.getRelevantConfig(issue)
//def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Yes", null)
//issue.setCustomFieldValue(cf, [option])
//issue.setCustomFieldValue(cf, "Yes")
//Kommentiert den Issue im Ziel Project, dass es sich um einen gecloned Issue handelt
doAfterCreate = {
def commentManager = ComponentAccessor.commentManager
commentManager.create(issue, currentUser, "This is a cloned issue from project HAM by ${currentUser.name}", true)
}
Hello,
Add logging to your script and have a look at the logs in the atlassian-jira.log file. Here is the info how you can find the log file:
https://confluence.atlassian.com/adminjiraserver073/logging-and-profiling-861253813.html
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueImpl
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
boolean status = false
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField myCustomField = customFieldManager.getCustomFieldObjectByName("field name 1")
String producttype = (String) issue.getCustomFieldValue(myCustomField)
IssueManager issueManager1 = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager1 = ComponentAccessor.getCustomFieldManager()
CustomField myCustomField1 = customFieldManager1.getCustomFieldObjectByName("field name 2")
String distribution = (String) issue.getCustomFieldValue(myCustomField)
log.error("producttype: ${producttype}")
log.error("distribution: ${distribution}")
if (producttype.equalsIgnoreCase("Approved") || producttype == null)
{
status=true
}
if (distribution.equalsIgnoreCase("Approved") || distribution == null)
{
status=true
}
return status
Hi @Alexey Matveev, thanks for the response. All these changes are already there in my Jira. I have some behavior scripts too, the logs for which I am able to see, but not this script.
Also the script is not working.
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.