My requirement is to simply copy the field values from epic to story during creation.
I am using a custom scripted post-function on the create issue transition.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = issue as MutableIssue
["Vendor Name", "Location", "Group", "GCRS Sector", "Impacted Regions"].each {
def cf = customFieldManager.getCustomFieldObjectByName(it)
def epic = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}
def value = epic.getCustomFieldValue(cf)
issue.setCustomFieldValue(cf, value)
}
as per the answers by @adammarkham here: https://community.atlassian.com/t5/Jira-questions/Using-a-behaviour-to-copy-a-multi-select-custom-field-from-an/qaq-p/579955#U668298
I am getting error at "cannot find matching method getCustomFieldValue"
def value = epic.getCustomFieldValue(cf)
Being new to scripts can you please point me towards some relevant document or example to get this resolved.?
Finally got the script working:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = issue as MutableIssue
["Vendor Name", "Location", "Group", "GCRS Sector", "Impacted Regions"].each { cfname ->
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == cfname}
def epicCf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}
if (!cf || !epicCf) {return}
def epic = issue.getCustomFieldValue(epicCf) as Issue
if (!epic) {return}
def cfValue = cf.getValue(epic)
issue.setCustomFieldValue(cf, cfValue)
}
Thanks Utkarsh. Your code helped me a lot. Actually i have a request to copy "Capitalizable?" from Epic to Story when story transitioning from Merged to Closes. Its working.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = issue as MutableIssue
["Capitalizable?"].each { cfname ->
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == cfname}
def epicCf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}
if (!cf || !epicCf) {return}
def epic = issue.getCustomFieldValue(epicCf) as Issue
if (!epic) {return}
def cfValue = cf.getValue(epic)
issue.setCustomFieldValue(cf, cfValue)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes! Thank you @Utkarsh Agarwal! This is exactly what I needed as a starting point to resolve the my issue as well!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is contained in the "epic" variable? It should contain the epic as an Issue object.
Can you try adding the following lines below the one where we get the epic
log.warn "Epic: $epic"
log.warn "Custom fields ${customFieldManager.getCustomFieldObjects(issue)*.name}"
What does that output in the logs?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Adam,
These logs returns:
Epic: Epic Link
Custom fields [Acceptance Criteria, Actual Time in Status, Add Comments, Additional Action, Additional Candidates, Additional Details, Adoption Status, Aggregate Story Points, Analysis Required, ...............................................]
The fields required are present in above logs. So this clears the doubt about connection with epic.
I guess the below method is not picking values:
epic.getCustomFieldValue(cf)
I am getting:
[Static type checking] - cannot find matching method
please check if the declared type is right or if the method exists.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Apologies, that script is slightly wrong. The example below should work for you:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = issue as MutableIssue
["Vendor Name", "Location", "Group", "GCRS Sector", "Impacted Regions"].each {
def cf = customFieldManager.getCustomFieldObjectByName(it)
def epicCf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}
def epic = epicCf.getValue(issue) as Issue
def cfValue = cf.getValue(epic)
issue.setCustomFieldValue(cf, cfValue)
}
First we need to get the epic as an Issue object from the epic-link custom field. Then we can copy the values over from the epic.
Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @adammarkham.
This really does fetch the values from the epic custom fields. However the values are not being set for the targeted story.
The fields i am trying to populate are of select list types. I tried to modified your code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = issue as MutableIssue
["Vendor Name", "Location", "Group", "GCRS Sector", "Impacted Regions"].each {
def cf = customFieldManager.getCustomFieldObjectByName(it)
def epicCf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}
def epic = epicCf.getValue(issue) as Issue
def cfValue = cf.getValue(epic)
def cfConfig = cf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {cfValue.toString()}
issue.setCustomFieldValue(cf, value)
log.error "Value: $value"
}
Still no luck. The post function is set at appropriate position:
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.
I Believe there is some issue to Set a select list custom field value
Even the below code does no seem to work:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = issue as MutableIssue
["Vendor Name"].each {
def cf = customFieldManager.getCustomFieldObjectByName(it)
def cfConfig = cf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Wipro'}
issue.setCustomFieldValue(cf, value)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
why "MutableIssue issue = issue" showing the error to me. why?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Utkarsh,
Please try, "def value = issue.getCustomFieldValue(cf)" it should work now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Praveen,
I tried this, however this picks the value from the story and maps it back to story.
My requirement is to have the custom field value taken from epic and mapped to story during issue creation.
Probably need to setup a connection between epic and story before mapping the values from epic to story.
Note: Fields context and custom fields are already present on screens for both epic and story.
Thanks
Utkarsh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.