how to clone a Jira issue multiple times, based on the Jira issue custom field values?

Manjunatha K R December 16, 2016

Hi,

I have a requirement to "clone a Jira issue multiple times", based on one Jira issue 'My components' custom field(i,e in this multiple components values will be updated by the user) values in the post function when a specific transition is executed successfully.

While cloning it, i have to update 'My components' custom field(i,e in this multiple components values will be updated by the user) value one by one into cloned PRs another custom field i,e sub-system.

For example if 'My components' custom field value = DB, Scripts, Dev in a JIRA issue INN-XXXX

We need to clone 3(THREE - it's based on number values present in 'My components' field) INN-???, INN-@@@ and INN-$$$$ JIRA issues by filling::

1) 'DB' value into "sub-system" custom field(i,e copied from My components' custom field value1)  in first Cloned JIRA issue,

2) 'Scripts' value into 2nd Cloned JIRA issue's "sub-system" custom field(i,e copied from My components' custom field value2)

3) 'Dev' value into 3rd Cloned JIRA issue's "sub-system" custom field(i,e copied from My components' custom field value3)

can someone advice, what is the best way to achieve this.

  • Manju

1 answer

1 vote
Thanos Batagiannis _Adaptavist_
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.
December 18, 2016

Hi Manju,

For a JIRA v7, you probably need something like 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption

Issue issue = issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

//assuming this is a multiple select list custom field
def componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Component CF")
def selectedComponents = issue.getCustomFieldValue(componentCF)

//assuming this is a select list (single choice)
def subSystemCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("sub-system")

//assuming this is a text field 
def textFieldA = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Text Field A")

selectedComponents?.each { LazyLoadedOption it ->
    def issueFactory = ComponentAccessor.getIssueFactory()
    def issueManager = ComponentAccessor.getIssueManager()
    def newIssue = issueFactory.cloneIssue(issue)

    // because the sub-system is a select list (single choice) we should find the option with that value (if any)
    def optionToSet = ComponentAccessor.getOptionsManager().getOptions(subSystemCF.getRelevantConfig(issue)).find {option -> option.value == it.value}

    // set the value of the custom sub-system and any other issue parameters you wish (project, assignee, etc)
    newIssue.setCustomFieldValue(subSystemCF, optionToSet)
    newIssue.setCustomFieldValue(textFieldA, "Just Text")

    Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
    issueManager.createIssueObject(currentUser, newIssueParams)

    log.info "Issue " + newIssue?.getKey() + " created"
}

Let me know if this does the trick.

regards, Thanos

Manjunatha K R January 5, 2017

Thanks for your prompt inputs Thanos, really it helps me.

I am using JIRA version 6.7.16 and Script runner version 4.1.3.16.

When I tried to execute the above script in my workflow post function (i,e Custom script post-function), got the error i,e Property 'newIssue?' not found before the transition itself. Due to this I removed the below line based on the other ticket responses seen on this same issue:

log.info "Issue ${newIssue?.getKey()} created" 

After this removing line, tried to re-execute my workflow transition (Eng Assigned to Fixed), executed successfully. But "Clone issues" are not created due to the below errors.

Is the above script syntax will change for my JIRA and Scripts runner version using???


Time (on server): Thu Jan 05 2017 16:37:03 GMT+0530 (India Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2017-01-05 16:37:03,671 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-01-05 16:37:03,672 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: INT-1659, actionId: 131, file: <inline script>
com.atlassian.jira.exception.CreateException: Error occurred while creating issue through workflow: 
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:754)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:645)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject(DefaultIssueManager.java:770)
	at com.atlassian.jira.issue.IssueManager$createIssueObject$1.call(Unknown Source)
	at Script1185$_run_closure1.doCall(Script1185.groovy:24)
	at Script1185.run(Script1185.groovy:15)
Caused by: [InvalidInputException: [Error map: [{}]] [Error list: [[Customer is required., Customer impact is required., Defect Source is required., Requirement id is required., Severity is required., Test Case id is required.]]]
	at com.googlecode.jsu.util.ValidatorErrorsBuilder.process(ValidatorErrorsBuilder.java:50)
	at com.googlecode.jsu.workflow.validator.GenericValidator.validate(GenericValidator.java:77)
	at com.atlassian.jira.workflow.SkippableValidator.validate(SkippableValidator.java:52)
	at com.opensymphony.workflow.AbstractWorkflow.verifyInputs(AbstractWorkflow.java:1512)
	at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1203)
	at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:615)
	at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:886)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:746)
	... 5 more
Manjunatha K R January 5, 2017

Except updating the "sub-system" custom field value from the parent JIRA issue's custom field individually into the Cloned issue, all other values should be copied from the parent issue.

So that below mandatory fields required while creating cloned issues should work fine.

But how to copy all the parent field values to cloned issue while creating ??

Customer is required., Customer impact is required., Defect Source is required., Requirement id is required., Severity is required., Test Case id is required
Caused by: [InvalidInputException: [Error map: [{}]] [Error list: [[Customer is required., Customer impact is required., Defect Source is required., Requirement id is required., Severity is required., Test Case id is required.]]]
Manjunatha K R January 5, 2017

One more additional comment, subsystem is Select List (single choice) data type defined in my project workflow.

//assuming this is a text custom field
def subSystemCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Subsystem")

 

Manjunatha K R January 5, 2017

Hi Thanos,

I tried to copy the mandatory custom field values from parent JIRA issue to Clone issue by modifying the script you had shared. But now I am getting the below JIRA version plug-in incompatibility error - please advice, how to resolve this??

Time (on server): Fri Jan 06 2017 13:04:20 GMT+0530 (India Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2017-01-06 13:04:20,683 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-01-06 13:04:20,683 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: INT-1669, actionId: 131, file: <inline script>
com.atlassian.jira.exception.CreateException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:757)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:645)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject(DefaultIssueManager.java:770)
	at com.atlassian.jira.issue.IssueManager$createIssueObject$1.call(Unknown Source)
	at Script1433$_run_closure1.doCall(Script1433.groovy:89)
	at Script1433.run(Script1433.groovy:69)
Caused by: com.atlassian.jira.workflow.WorkflowException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB
	at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:923)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:746)
	... 5 more
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.jira.issue.customfields.option.Option
	at com.atlassian.jira.issue.customfields.impl.SelectCFType.getDbValueFromObject(SelectCFType.java:72)
	at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(AbstractSingleFieldType.java:161)
	at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:854)
	at com.atlassian.jira.workflow.function.issue.IssueCreateFunction.execute(IssueCreateFunction.java:88)
	at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050)
	at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446)
	at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:615)
	at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:886)
	... 6 more

 

Modified Script using in my workflow is as below/FUR::

===========================================

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.MutableIssue

Issue issue = issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

//assuming this is a multiple select list custom field
def componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impacted Sub-Systems")
def selectedComponents = issue.getCustomFieldValue(componentCF)

//Customer, Customer impact, Defect Source, Priority, Requirement id, Server Component, Server Release, Server Release tag, Severity, Test Case id
def Customer = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer")
def selectedCustomer = issue.getCustomFieldValue(Customer)

def CustomerC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer")

def CustomerImp = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer impact")
def selectedCustomerImp = issue.getCustomFieldValue(CustomerImp)

def CustomerImpC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer impact")

def defectsource = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Defect Source")
def selecteddefectsource = issue.getCustomFieldValue(defectsource)

def defectsourceC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Defect Source")

def Priority = issue.getPriority()

def Severity = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Severity")
def selectedSeverity = issue.getCustomFieldValue(Severity)

def SeverityC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Severity")

def Requirementid = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Requirement id")
def selectedRequirementid = issue.getCustomFieldValue(Requirementid)

def RequirementidC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Requirement id")

def ServerComponent = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Component")
def selectedServerComponent = issue.getCustomFieldValue(ServerComponent)

def ServerComponentC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Component")

def ServerRelease = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Release")
def selectedServerRelease = issue.getCustomFieldValue(ServerRelease)

def ServerReleaseC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Release")

def ServerReleasetag = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Release tag")
def selectedServerReleasetag = issue.getCustomFieldValue(ServerReleasetag)

def ServerReleasetagC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Release tag")

def TestCaseid = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Case id")
def selectedTestCaseid = issue.getCustomFieldValue(TestCaseid)

def TestCaseidC = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Case id")


//assuming this is a text custom field
def subSystemCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Subsystem")

selectedComponents?.each { LazyLoadedOption it ->
def issueFactory = ComponentAccessor.getIssueFactory()
def issueManager = ComponentAccessor.getIssueManager()
def newIssue = issueFactory.cloneIssue(issue)

// set the value of the custom sub-system and any other issue parameters you wish (project, assignee, etc)
newIssue.setCustomFieldValue(subSystemCF, it.value)
newIssue.setCustomFieldValue(CustomerC, selectedCustomer)
newIssue.setCustomFieldValue(CustomerImpC, selectedCustomerImp)
newIssue.setCustomFieldValue(defectsourceC, selecteddefectsource)
//newIssue.setCustomFieldValue(PriorityC, selectedPriority)
newIssue.setPriority(Priority)
newIssue.setCustomFieldValue(SeverityC, selectedSeverity)
newIssue.setCustomFieldValue(RequirementidC, selectedRequirementid)
newIssue.setCustomFieldValue(ServerComponentC, selectedServerComponent)
newIssue.setCustomFieldValue(ServerReleaseC, selectedServerRelease)
newIssue.setCustomFieldValue(ServerReleasetagC, selectedServerReleasetag)
newIssue.setCustomFieldValue(TestCaseidC, selectedTestCaseid)

Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
issueManager.createIssueObject(currentUser, newIssueParams)
}

Manjunatha K R January 5, 2017

FYR ...

'Customer' is a "Select List (single choice)"

'Customer impact' is a "Select List (single choice)"

'Defect Source' is a "Select List (single choice)"

'Priority' is a "Jira default field"

'Requirement id' is a "Text Field (multi-line)"

'Server Component' is a "Select List (single choice)"

'Server Release' is a "Select List (single choice)"

'Server Release tag' is a "Select List (single choice)"

'Severity' is a "Select List (single choice)"

'Test Case id' is a "Text Field (multi-line)"

In case copying from parent JIRA issue custom field value to clone issue custom field values, is of suspect for this issue posted.

Thanos Batagiannis _Adaptavist_
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.
January 10, 2017

Hi Manju,

I updated the script above to match your requirements - the sub system custom field as a select list (single choice)

Now you can see hoe to set an option to a select list, follow this to set options to the other single select fields you have. 

Also added an example of setting a value to a text field (single or multi line)

Hope this solves your issue.

regards, Thanos

manjunatha k r January 10, 2017

Thank you very much for your inputs Thanos.

Will test and re-update the progress. Thanks again

Manjunatha K R January 11, 2017

Thanos,

Based on your inputs, I modified the inline script to fill the required Select List (single choice) custom fields, Text field values mandated in my workflow as below.

I am able to get the number of cloned issues created based on the "Impacted sub-systems" i,e  custom field values filled in it now. And I am not able to see the "is cloned by" and "clones" issues link established from parent to newly cloned issues and vice versa respectively.  

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
 
Issue issue = issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
 
//assuming this is a multiple select list custom field
def componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impacted sub-systems")
def selectedComponents = issue.getCustomFieldValue(componentCF)


def componentCF1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Defect Source")
def selectedComponents1 = issue.getCustomFieldValue(componentCF1)
def componentCF2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer")
def selectedComponents2 = issue.getCustomFieldValue(componentCF2)
def componentCF3 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer impact")
def selectedComponents3 = issue.getCustomFieldValue(componentCF3)
def componentCF4 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Component")
def selectedComponents4 = issue.getCustomFieldValue(componentCF4)
def componentCF5 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Release")
def selectedComponents5 = issue.getCustomFieldValue(componentCF5)
def componentCF6 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Server Release tag")
def selectedComponents6 = issue.getCustomFieldValue(componentCF6)
def componentCF7 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Severity")
def selectedComponents7 = issue.getCustomFieldValue(componentCF7)
def Priority = issue.getPriority()
 
//assuming this is a select list (single choice)
def subSystemCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Subsystem")
 
//assuming this is a text field
def textFieldA1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Case id")
def textFieldA2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Requirement id")


selectedComponents?.each { LazyLoadedOption it -&gt;
    def issueFactory = ComponentAccessor.getIssueFactory()
    def issueManager = ComponentAccessor.getIssueManager()
    def newIssue = issueFactory.cloneIssue(issue)
 
    // because the sub-system is a select list (single choice) we should find the option with that value (if any)
    def optionToSet = ComponentAccessor.getOptionsManager().getOptions(subSystemCF.getRelevantConfig(issue)).find {option -&gt; option.value == it.value}


    /* // As this below method of updating custom field doesn't work, I removed it.
    def optionToSet1 = ComponentAccessor.getOptionsManager().getOptions(componentCF1.getRelevantConfig(issue)).find {option -&gt; option.value == selectedComponents1}
    def optionToSet2 = ComponentAccessor.getOptionsManager().getOptions(componentCF2.getRelevantConfig(issue)).find {option -&gt; option.value == selectedComponents2}
    def optionToSet3 = ComponentAccessor.getOptionsManager().getOptions(componentCF3.getRelevantConfig(issue)).find {option -&gt; option.value == selectedComponents3}
    def optionToSet4 = ComponentAccessor.getOptionsManager().getOptions(componentCF4.getRelevantConfig(issue)).find {option -&gt; option.value == selectedComponents4}
    def optionToSet5 = ComponentAccessor.getOptionsManager().getOptions(componentCF5.getRelevantConfig(issue)).find {option -&gt; option.value == selectedComponents5}
    def optionToSet6 = ComponentAccessor.getOptionsManager().getOptions(componentCF6.getRelevantConfig(issue)).find {option -&gt; option.value == selectedComponents6}
    def optionToSet7 = ComponentAccessor.getOptionsManager().getOptions(componentCF7.getRelevantConfig(issue)).find {option -&gt; option.value == selectedComponents7}
    */

    // set the value of the custom sub-system and any other issue parameters you wish (project, assignee, etc)
    newIssue.setCustomFieldValue(subSystemCF, optionToSet)
    newIssue.setCustomFieldValue(componentCF1, selectedComponents1)
    newIssue.setCustomFieldValue(componentCF2, selectedComponents2)
    newIssue.setCustomFieldValue(componentCF3, selectedComponents3)
    newIssue.setCustomFieldValue(componentCF4, selectedComponents4)
    newIssue.setCustomFieldValue(componentCF5, selectedComponents5)
    newIssue.setCustomFieldValue(componentCF6, selectedComponents6)
    newIssue.setCustomFieldValue(componentCF7, selectedComponents7)    
    
    newIssue.setCustomFieldValue(textFieldA1, "Test Case id1")
    newIssue.setCustomFieldValue(textFieldA2, "Requirement id1")
    newIssue.setPriority(Priority)
    
    Map&lt;String,Object&gt; newIssueParams = ["issue":newIssue] as Map&lt;String,Object&gt;
    issueManager.createIssueObject(currentUser, newIssueParams)
}
Manjunatha K R January 11, 2017

Hi Thanos,

Since from yesterday, was trying to create Issue links from a "parent JIRA issue to all Cloned issues" successfully created, based on one of Atlassian community response shared it before as below

def LinkTypeName = "Cloners"
 
selectedComponents?.each { LazyLoadedOption it -&gt;
    def issueFactory = ComponentAccessor.getIssueFactory()
    def issueManager = ComponentAccessor.getIssueManager()
    def newIssue = issueFactory.cloneIssue(issue)
....................
....................
Map&lt;String,Object&gt; newIssueParams = ["issue":newIssue] as Map&lt;String,Object&gt;
Issue newIssue1 = issueManager.createIssueObject(currentUser,newIssueParams)
 
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
IssueLinkManager issueLinkManager = ComponentAccessor.getInstance().getIssueLinkManager()
 
//Newly added coded based on the old Atlassian community response
if(newIssue1 == null) {
	log.error("error creating new issue");
}
else {
	// Set link
	//IssueLinkType iLinkType = findIssueLinkTypeByName(ISSUE_LINK_TYPE_NAME);
def iLinkType = issueLinkTypeManager.getIssueLinkTypesByName(LinkTypeName) 

	if(iLinkType == null) {
		log.error("IMPOSSIBLE TO LINK ISSUE " + issue.getKey());
	}
	else {
		issueLinkManager.createIssueLink(issue.getId(), newIssue1.getId(), 			iLinkType.getId(), Long.valueOf(0), currentUser);
		}
	}

But getting the following ERRORs ... and tried to resolve it, but not succeeded...

1) can't find matching method for issue.getId(), etc

2) can't find matching method for issueLinkManager.createIssueLink

3) can't find matching method ComponentAccessor.getInstance()

Even I tried to import the below interface classed needed.

import com.atlassian.jira.issue.link.DefaultIssueLinkTypeManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkType
import com.atlassian.jira.issue.link.IssueLinkTypeManager

Manjunatha K R January 12, 2017

Hi Thanos,

One more additional input is needed from your side.

How to copy custom field values from a parent JIRA issue to cloned issues of data type Radio Button and User Picker (multiple users) for the required custom fields in my workflow to get completed.

Radio Button ....
1) MOP Impact  - custom field 1
2) USER DOC IMPACT  - custom field 2

User Picker (multiple users)....
1) Release Prime  - custom field 3

Manjunatha K R January 12, 2017

Hi Thanos,

I am able to create issue link successfully using the below additional code now.

Thank you very much for your timely support, it really helped me to learn and proceed with my workflow enhancements on time now.

Please advice on "How to copy custom field values from a parent JIRA issue to cloned issues of data type Radio Button and User Picker (multiple users),Select List (multiple choices)" for the required custom fields in my workflow to get completed.

Radio Button ....
1) MOP Impact  - custom field 1
2) USER DOC IMPACT  - custom field 2

User Picker (multiple users)....
1) Release Prime  - custom field 3

Select List (multiple choices) ....

1) Fixed in Release - custom field 4
2) Fixed In Tag - custom field 5

The Source custom field data type(i,e Parent JIRA issue) and destination custom field data types(i,e Cloned JIRA issues) are of same type as above. 

  • Manju

 

IssueLinkManager linkManager = ComponentManager.getInstance().getIssueLinkManager()
          
    Collection&lt;IssueLinkType&gt;     issueLinkTypes1=ComponentAccessor.getComponentOfType(IssueLinkTypeManager.class).getIssueLinkTypes();
    String linkID=null;
    for (IssueLinkType linktype : issueLinkTypes1) {
        String name=linktype.getName();
        log.warn("Issue Link Type Name : " + name);
        String id=linktype.getId();
        log.warn("Issue Link Type Id : " + id);
          
        if(name.equals("Cloners")){// change link name here
            linkID=linktype.getId();
            break;
        }
    }//for end
    log.warn("Issue Link Types : " + IssueLinkType)
    linkManager.createIssueLink(issue.getId(), newIssue.getId(),        Long.parseLong(linkID),Long.valueOf(0), currentUser);
  
}//each end
Manjunatha K R January 13, 2017

Hi Thanos,
I am able to fill the needed custom fields now in my workflow. Thanks again for your prompt inputs to make my workflow complete.
One last doubt on how to check whether 'Impacted sub-systems' is a 'None' (is a default value) value or not.
why because if it's 'None' default value, I no need to create clone issues and create link in my post function. Only if it has values other than default value only I need to create clone issues.
Please advice me on how to do this, I tried the below options, didn't succeeded. Thanks.

def componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impacted sub-systems")
def selectedComponents = issue.getCustomFieldValue(componentCF)

if (selectedComponents == 'None')
{
log.info ("No need to create clone as Impacted sub-systems value is None")
}else
{
log.info ("Creating clones as Impacted sub-systems value is not None")
.......
......
}

OR
if ('None' in cfValues['Impacted sub-systems']*.value) {
log.info ("No need to create clone as Impacted sub-systems value is None")
}else{
log.info ("Creating clones as Impacted sub-systems value is not None")
.......
......
}
Manjunatha K R January 30, 2017

Hi Thanos,

One basic doubt/clarification, using the above updated script I am successfully able to create the number of cloned issues based on the custom field(i,e Impacted sub-systems) values.

But when I update the 'Subsystem' field value of Cloned issue(s) from the 'Impacted sub-systems' values one by one. In Subsystem custom field, we have a Validation Script(i,e Add-on->Behaviours->Subsystem) written to map subsystem - module owner custom field value as below.

But I am unable to get the specific subsystem respective 'module owner' custom field values updated into Cloned issues from the already existing Validation Script - why it's so???

is we need to copy "module owner" field values into our cloned issues by writing the below similar kind of script by matching the "subsystem to module owner values" mapped??

Please confirm on the same... or Do you any other suggestions to achieve the same using the above script?

import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
FormField formComponent = getFieldById(fieldChanged)
FormField formSubcomponent = getFieldByName ("Module Owner")
FormField Release_Prime = getFieldByName ("Release Prime")
def actionName = getActionName()
def actionId = getAction().getId() 
def componentFormValue = formComponent.getFormValue()
def componentValue = ""
def relPrimeVal=""

if((actionId == null &amp;&amp; actionName == null)||(actionId == 1 &amp;&amp; actionName == "Create" )|| (actionId == 1431 &amp;&amp; actionName == "Change Subsystem")|| (actionId == 1441 &amp;&amp; actionName == "Clone PR"))
{
 formComponent.setReadOnly(false)
 switch (componentFormValue) {
  case "10030" : //Agent
 componentValue = "Platform-Support" 
     relPrimeVal="Server-release"
   break
  
  case "10031" : //Automation tool
   componentValue = "automation"
     relPrimeVal="Server-release"
   break
case "-1" :
   componentValue = "kkdhu"
     relPrimeVal="Server-release"
  break
 .............
 .............

 }
 formSubcomponent.setFormValue(componentValue)
    Release_Prime.setFormValue(relPrimeVal)
}
else
{
    formComponent.setReadOnly(true)
     Release_Prime.setReadOnly(true)
}
 
/* The custom field "Module Owner" is defined as below in 'Add-on-&gt;Behaviours-&gt; Module Owner' */
 
Field: Module Owner

Optional (Require) 
Readonly (Writable) 
Shown (Hide)
Manjunatha K R March 22, 2017

All,

I am getting the below error using the Auto Clone script discussed in this Q&A thread after upgraded my JIRA s/w to 7.2.7 version from 6.7.16 JIRA version.

But same script works perfectly fine, when I was using my old JIRA 6.7.16 version.

org.ofbiz.core.entity.GenericTransactionException: Commit failed, rollback previously requested by nested transaction.

Right now I am Using Adaptavist ScriptRunner for JIRA is 4.3.16 and JIRA s/w version is 7.2.7.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.DefaultIssueLinkTypeManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkType
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.IssueManager

log.setLevel(org.apache.log4j.Level.DEBUG)

Issue issue = issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

String componentValue = null, relPrimeVal= null;

IssueLinkTypeManager issueLinkTypeManager = ComponentManager.getComponentInstanceOfType(IssueLinkTypeManager.class)

def Priority = issue.getPriority()
def Asignee = issue.getAssignee()

for (int i =0 ; i &lt; casecadingValueCount; i++){    
    def issueFactory = ComponentAccessor.getIssueFactory()
    def issueManager = ComponentAccessor.getIssueManager()
    def newIssue = issueFactory.cloneIssue(issue)

	newIssue.setPriority(Priority)
    
    newIssue.setSummary("CLONE - $issue.summary")
    newIssue.setProjectId(issue.projectId)
    newIssue.setDescription(issue.description)
    newIssue.setAssigneeId("Asignee")
    

    Map&lt;String,Object&gt; newIssueParams = ["issue":newIssue] as Map&lt;String,Object&gt;
    issueManager.createIssueObject(currentUser, newIssueParams)
    
          
    IssueLinkManager linkManager = ComponentAccessor.getIssueLinkManager()
    //Issue testGroupIssue = issueManager.getIssueObject(issue.id);
    //Issue testGroupIssue1 = issueManager.getIssueObject(newIssue.id);
    
    Collection&lt;IssueLinkType&gt; issueLinkTypes1=ComponentAccessor.getComponentOfType(IssueLinkTypeManager.class).getIssueLinkTypes();
    String linkID=null;
    for (IssueLinkType linktype : issueLinkTypes1) {
        String name=linktype.getName();
        log.warn("Issue Link Type Name : " + name);
        String id=linktype.getId();
        log.warn("Issue Link Type Id : " + id);
        
        if(name.equals("Cloners")){// change link name here
            linkID=linktype.getId();
            break;
        }
    }
    log.warn("Issue Link Types : " + IssueLinkType)
    log.info("createIssueLink: i")
    log.info(i)
    
    linkManager.createIssueLink(newIssue.getId(), issue.getId(), Long.parseLong(linkID),Long.valueOf(0), currentUser);
           
}//selectedComponents or for loop end

 

Please advice what is the issue.

  • Manju
Manjunatha K R March 22, 2017

My workflow is as below::

Create-> Eng Supp -> Eng Assigned -> Eng Fixed -> Closed.

The above posted post function script is added as part of "Eng Fixed" transition's post function, when we transition from Eng Assigned state. On post transition to Eng Fixed, Clone Issue(s) will be created based on some custom field values updated in it and linked to the original issue using "is Cloned by" link as per the above script.

But in "Create-> Eng Support" transition's post function, I added one another Fast-track transition an issue post function - but same is working in my older version JIRA 6.7.x before JIRA upgrade was done to 7.2.7 version and giving the below ERROR.

2017-03-23 13:10:28,519 ERROR [utils.WorkflowUtils]: Errors: {}
Error Messages: [Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB java.lang.String cannot be cast to java.util.Collection]
Start of logs truncated as they exceeded 300 lines.

Right now I am using Adaptavist ScriptRunner for JIRA is 4.3.16 and JIRA s/w version is 7.2.7.

Fast-track transition an issue post function is as below::

Condition::

cfValues['Defect Source']?.value == 'ITG' || cfValues['Defect Source']?.value == 'ITG-Traffic' || cfValues['Defect Source']?.value == 'MTG_TRAFFIC' || cfValues['Defect Source']?.value == 'ITG-Automation' || cfValues['Defect Source']?.value == 'Design Server' || cfValues['Defect Source']?.value == 'MTG' || cfValues['Defect Source']?.value == 'FOA' || cfValues['Defect Source']?.value == 'Requirements' || cfValues['Defect Source']?.value == 'System Engineering'

Action: Assign to Engineering (231)

 

If I remove this Fast-track transition an issue post function, Cloning of issues will work in my Eng Fixed post function script works perfectly fine and Cloned issues will remain in Eng Support state only as I removed the above Fast-track transition an issue post function. But I need the above Fast-track transition an issue post function to transition the issues from Eng Support to Eng Fixed in the condition I added as part of the above Fast-track transition an issue post function.

Due to which I am unable to create cloned issues and link it, using another post function in my workflow.

Same works in my older version JIRA s/w. Please suggest what is causing this issue in new JIRA version used.

Is there any known issue/work around needed in ScriptRunner workflow post function Fast-track transition an issue post function using 7.2.7 JIRA s/w version ???

  • Manju

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events