We have some custom fields that capture date/time and user that executed some transitions. when cloning an issue these fields are also cloned. If I put a post function on the Create event in the workflow for that issue type to clear them will that be executed when the issue is cloned or is another create process used when cloning?
I tested clearing the fields and it works.
JIRA Clone-Plus plugin supports excluding fields from cloning.
Will that not also clear the fields when user creates an issue and fills in those fields? Oh, but, I see you are only talking about transition specified fields.
>put a post function on the Create event in the workflow >for that issue typeThis works for me. I added a post function "clear issue field" into the "Create" transition. Now when I clone an issue the field is cleared.Note: the field is also cleared when a brand new issue is created. This is fine with my workflow.
Unfortunatly, this will also clear the value that the user enteres on a Create so this is not acceptalbe for my use. For example, the field that I want to clear is a "Screen" flag which indicates an issue has been screened. But ofen-times, managers want to mark an issue screened when they create it. So, using a POST function on the create will clear this for both Create and Clone which is no good.
If you never want to set the field during a create step, I suppose it can work but not if you want to control just the Clone operation. I am still looking for a way to do this.
It seems odd that the "Create" action is only accesable from the Design screen and not the "Steps" workflow edit screens but it did work for me. I was able to clear a number of Custom fields (using JiraSuiteUtils) in the create action.
Clear value (post-function) is works great on custom fiels but not on system fields LABELS.
Any idea why ?
That is true but it is not a free option.
Dumb question, but how do I edit that? When editing workflows I only see transitions from Open on.
Ignore that, found it. Need coffee badly.
It also doesn't work for Read-Only fields.
Without paying for an add-on, or doing risky database modifications, JIRA does not appear to provide a solution to this problem.
@Joe Pitt I have a same requirement to unset assignee when you clone but i don't see "Clear Field Value" in post function. Can you please help?
error.JPG
Hi Guys,
I am facing same issue too, (field getting cleared soon after issue is created).
Is there any way we can accomplish this (without using clone+ ) in the ways like re-ordering post functions
See useful answers here:
https://community.atlassian.com/t5/Answers-Developer-Questions/Condition-to-check-if-issue-is-cloned-vs-initial-creation-to/qaq-p/570243
I've created a post-function that implements Thanos' suggestion from the link I shared above.
Some observations:
1. It works (duh!)
2. In the post-functions definition, the script must be placed AFTER the action 'Create the issue originally'.
3. For debug, I pop up a user message box. It shows up in issue creation, but not during issue cloning. This is weird, but the code works.
HTH, Amir
Hi Amir,
I would appreciate your full script doing that. My script apparently works fine but when i see, the script has not done anything.
Thanks in advance,
Regards
Here it is:
// Note: Not sure whether all imports are required, it's a cut & paste from other scriptsimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.ComponentManagerimport com.atlassian.jira.issue.CustomFieldManagerimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderimport com.atlassian.jira.project.Projectimport com.atlassian.jira.user.util.UserUtilimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.event.issue.IssueEventBundleimport com.atlassian.jira.event.issue.IssueEventManagerimport com.atlassian.jira.event.issue.IssueEventBundleFactoryimport com.atlassian.jira.event.issue.IssueEventimport webwork.action.ActionContextimport java.time.*import java.time.format.DateTimeFormatterimport com.onresolve.scriptrunner.runner.util.UserMessageUtildef debugMode = false as Booleandef msgDebugfinal String scriptName = "CCB-Post-01: "DateTimeFormatter dtFormatter = DateTimeFormatter.ofPattern(" @ yyyy-MM-dd HH:mm:ss ")def dateTimeNowdateTimeNow = LocalDateTime.now().format(dtFormatter)def is_cloner = falsedef request = ActionContext.getRequest()if (request) { msgDebug = scriptName + "Issue was created manually" + dateTimeNow + "[D03]" UserMessageUtil.info(msgDebug)} else {msgDebug = scriptName + "Issue was created via CLONE action" + dateTimeNow + "[D04]"UserMessageUtil.info(msgDebug)is_cloner = true}if (!is_cloner) {return true}def changeHolder = new DefaultIssueChangeHolder()def issueManager = ComponentAccessor.getIssueManager()def Reviewed_by_CF = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_12345")def Reviewed_by_Value = issue.getCustomFieldValue("customfield_12345")// Clear custom field valueReviewed_by_CF.updateValue(null, issue, new ModifiedValue(Reviewed_by_Value, null), changeHolder)// Update issue and fire "Issue Updated" eventissueManager.updateIssue(null, issue, EventDispatchOption.ISSUE_UPDATED, false)true
Hello,
When doing a Clone to another project, are you able to get the project key of the new project being cloned into?
I've been searching and testing all day.
issueContext.projectObject.key - Always returns the key of the issue being cloned from.
I tried variations of getFieldByName and getFieldByID with project/projects/Project/Projects and it always returns nulls.
Thanks in advance.
Hey @JacksonC , I suggest you post a new question to the forums (with a new subject line) as this thread has been answered.
I am interested in the answer...
Amir
Try this and let me know if it works:
import com.atlassian.jira.project.Project
Project project = issue.getProjectObject()def projectKey = project.getKey()
def projectManager = ComponentAccessor.getProjectManager()def projectObj = projectManager.getProjectObjByKey(projectKey)
Thank you for your suggestion. I just tried it and it did not work.
It still gets the project key of the project being cloned from.
I've posted a new question here: https://community.atlassian.com/t5/Jira-questions/How-to-get-new-project-key-on-Clone-Plus-plugin-with-Behaviours/qaq-p/1274969#U1275237
I've also opened a support ticket with Clone Plus.
I'll note down in the post above what I find.
I had a similar need which I found only parts of solution of (by @Thanos Batagiannis). I thought someone else might want it soon enough and will stumble on this precise place where my research begun.Additional problem I had was that I needed to set my custom field to it's default value, not only clear it, since one configuration have one of a few checkboxes checked as default value.
This implementation works when added as Scriptrunner Custom Script postfunction in my Create transition. Jira Server 8.13.1
//This post function must(?) be placed before post function "Creates the issue originally."//***Perform tasks when cloning***import com.atlassian.jira.component.ComponentAccessor//Bunch of includes that might be useful for other Custom Field Types ... or not?//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.FieldConfigimport webwork.action.ActionContext//Get custom fielddef customFieldManager = ComponentAccessor.getCustomFieldManager()def cf = customFieldManager.getCustomFieldObjectsByName("Relaxing name")[0]//Get field config and custom field type default value//https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-get-custom-field-s-default-value-for-validator-script/qaq-p/506707def fieldConfig = cf.getRelevantConfig(issue)def cfType = customFieldManager.getCustomFieldTypes().find {it.name == "Checkboxes"}def rnDefault = cfType?.getDefaultValue(fieldConfig)log.debug("Default value : ${cfType?.getDefaultValue(fieldConfig)}")//Initial creation results in request, Cloning doesn't. Ugly but seams to be the way to do this.//https://community.atlassian.com/t5/Answers-Developer-Questions/Condition-to-check-if-issue-is-cloned-vs-initial-creation-to/qaq-p/570243def request = ActionContext.getRequest()if (request) { //issue.setCustomFieldValue(cf, rnDefault) log.debug("Manually Created issue") return true} else { issue.setCustomFieldValue(cf, rnDefault) log.debug("Cloned issue") return true}
What is the post-function name to add this script?
From which version we have this feature to exclude the fields from cloning?
Just coming back to say I still need coffee.
@Jonas Frid I tried your script and it fails based on this:
Cannot invoke method getRelevantConfig() on null object
Thoughts?
Here is the script that I use to clear a field when an issue of a specific type (in this case Epic) is cloned:
/* This example ScriptRunner custom listener script must be configured to fire on the 'IssueLinkCreatedEvent' Event. It shows how when an issue is cloned that you can clear the value of a custom field on the cloned issue. Closely based on: https://community.atlassian.com/t5/Jira-questions/I-want-to-clear-the-field-value-during-the-clone-of-the-issue/qaq-p/1550276*/// This Script Listener should be configured to run on the Issue Link Created Eventimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.issue.CustomFieldManagerimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.link.IssueLinkimport com.atlassian.jira.user.ApplicationUserimport org.slf4j.Logger;import org.slf4j.LoggerFactory;String ISSUE_TYPE_ID = "6" // ID for an EpicLong CUSTOM_FIELD_ID = 11406 // ID for the custom field (a checkbox)public class IssueCreatedResolvedListener { private static final Logger log = LoggerFactory.getLogger(IssueCreatedResolvedListener.class);}// Check if the type of the issue link type of the issue is 'Cloners' which is the issue link type that Jira uses when cloning an issue. // If it is a cloned issue of type Epic, then perform the logic to clear field valuesIssueLink issueLink = event.getIssueLink()if (issueLink.issueLinkType.name == "Cloners"){ MutableIssue issue = issueLink.getSourceObject() if (issue) { if (issue.getIssueType().getId() != ISSUE_TYPE_ID) { //log.info("The issue is not an Epic, so skipping") return } log.info("The Epic has been cloned, so now removing the values from the fields which should not be set") IssueManager issueManager = ComponentAccessor.getIssueManager() CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() CustomField textCustomField = customFieldManager.getCustomFieldObject(CUSTOM_FIELD_ID) issue.setCustomFieldValue(textCustomField, null) issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false) }// If the issue is not a clone, then log a message saying this and do nothing}else{ //log.info("The issue has not been cloned so do nothing")}
It looks like you're new here. Sign in or register to get started.