groovy script for copying a custom field value from an associated issue to EPIC's custom field

Hi,

I am using the below script to copy a custom field value set from an associated issue to EPIC's custom field. But I am getting the below error and unable to get the value in EPIC's custom. Please advice, what it's wrong in my script.

2017-03-15 20:13:21,907 WARN [workflow.ScriptWorkflowFunction]: 
{customfield_10715=Invalid value 'YES' passed for customfield 'Global XLS Update Impacted'. Allowed values are: 13624[YES], 13625[NO], -1}

Trying to copy "Global XLS Update IMPACT" set custom field from an associated issue to EPIC custom field "Global XLS Update Impacted" of Radio button date type has YES, NO values configured as default values in it.

Based on Associated issue value set, has to be copied into EPIC's custom field.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
log.setLevel(org.apache.log4j.Level.DEBUG)
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.customfields.option.Option

def issue = issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueService = ComponentAccessor.getIssueService()

def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")

def epicLink = issue.getCustomFieldValue(epicLinkCf) as Issue

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
 
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def cascade3 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Global XLS Update IMPACT") //Associated issue's custom field name; Radio button date type

def cascade99 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Global XLS Update Impacted") //EPIC's custom field name; Radio button date type

String cfVal3 = issue.getCustomFieldValue(cascade3)

String optionToSet1 = ComponentAccessor.getOptionsManager().getOptions(cascade99.getRelevantConfig(epicLink)).find {option -> option.value == cfVal3}

issueInputParameters.addCustomFieldValue("customfield_10715", optionToSet1) //customfield_10715 is custom field id of EPIC's custom field i,e Global XLS Update Impacted

def updateValidationResult = issueService.validateUpdate(currentUser, epicLink.id, issueInputParameters)
 
    if (updateValidationResult.isValid()) {
        issueService.update(currentUser, updateValidationResult)
    } else {
        log.warn updateValidationResult.errorCollection.errors
    }
  • Manju

1 answer

1 accepted

I got the needed solution and modified the below 2 lines to pass the optionId now as below::

with this, able to update the value to EPIC's custom field successfully now. Thanks.

def 
optionToSet1 = 
ComponentAccessor.getOptionsManager().getOptions(cascade99.getRelevantConfig(epicLink)).find
 {option -> option.value == cfVal3}

String  optionToSet2 = optionToSet1.optionId
issueInputParameters.addCustomFieldValue("customfield_10715", optionToSet2) //customfield_10715 is custom field id of EPIC's custom field i,e Global XLS Update Impacted

Hi Manjunath,

Do you know how to validate custom field value from the linked issue while linking to other issue on create screen?

Test112.PNG

Lets just say I want to create new bug, and is having "Cause"[select type single choice] field contains "Product Feature" and "Technical Feature". 

If user select 'Cause' field as 'Product Feature' then require at least one 'Issue Link' with relationship of "Is Caused By" must exist and must have a linked GTN Epic of where the Epic's 'Feature Type' field has the value of 'Product Feature'.

Ex: Need to validate weather 'GTN-28761' has 'Feature Type' of 'Product Feature' or not  

I am new to groovy, can you help me please

Thanks

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,312 views 14 20
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot