Behaviours's Validation Script(i,e Add-on->Behaviours->"Customfield") not enacted during the clone of multiple issues

Manjunatha K R January 31, 2017

Hi,

Behaviours's Validation Script(i,e Add-on->Behaviours->"Customfield") not enacted during the clone of multiple issues using groovy script

Is there a way to achieve it?

When I create multiple clone issues using my groovy script, all Cloned issues are created successfully but Behaviours's Validation Script(i,e Add-on->Behaviours->Subsystem) written to map subsystem - "module owner" custom field value is not getting updated successfully in new issues.
is this not possible to enact using Behaviours Plugin Validation Script - when cloning issues using my below groovy script::


I believe cloneIssue() and createIssueObject() function will work with the condition added i,e (actionId == 1 && actionName == "Create" ) as part of my Validation Script(i,e Add-on->Behaviours->Subsystem) written to map subsystem - module owner custom field value.

/* clone of multiple Jira issues created using the below groovy script snipet in one of my project workflow, post function*/

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("Subsystem") 

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) 
 
Map newIssueParams = ["issue":newIssue] as MapIssue newIssue1 = issueManager.createIssueObject(currentUser,newIssueParams) 
 
-------------------- 
}
/* Validation Script(i,e Add-on->Behaviours->Subsystem) written to map subsystem - "module owner" custom field value */
 
import org.ofbiz.core.entity.GenericValueimport com.atlassian.jira.issue.customfields.manager.OptionsManagerFormField
 
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 && actionName == null)||(actionId == 1 && actionName == "Create" )|| (actionId == 1431 && actionName == "Change Subsystem")|| (actionId == 1441 && actionName == "Clone PR") ||(actionId == 771 && actionName == "Clone for All")|| (actionId == 811 && actionName == "Clone for All")|| (actionId == 1101 && actionName == "Restricted Update")|| (actionId == 1081 && actionName == "Restricted Update")){
 
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 = "kkadhu"    
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->Behaviours-> Module Owner' */
 
Field: Module Owner
Optional (Require)
Readonly (Writable)
Shown (Hide)

1 answer

0 votes
JamieA
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.
February 3, 2017

You've asked this several times already.

Manjunatha K R February 3, 2017

Yes Jamie, I agree.

In context of getting different scenarios clarification, I created this ticket.

Sorry for the confusion. Will discuss this same context in other ticket, where you had shared your feedback. Thanks.

Suggest an answer

Log in or Sign up to answer