Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Customfield_102090 is a required field.
My Requirement is :
when i am creating a story then Customfield_102090 value from Epic should copy to the story .
What i am facing :
since the field is required when i am creating a story it fails because my groovy copy script is in post function.
how can i bypass Required field either by copying the field or any other method .Any help is helpful .
Let me know if you want to know more info .
@Mark Markov Why do you need to make that field required if you dont put it on the screen and pass the value in the postfunction?
Other solution is to make an option default in the customfield and set it required in Field Configuration. This way you dont need to put it on the screen and the script postfunction should work without problems.
If you need it, here is the Script Postfunction to copy the value from an epic. You should put it on the last position in postfunctions on create transition.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def epicLink = customFieldManager.getCustomFieldObject(10102L)
def epic = issue.getCustomFieldValue(epicLink) as Issue
def customField = customFieldManager.getCustomFieldObject(10110L) // Your CF
def cfEpicValue = epic.getCustomFieldValue(customField)
if (epic) {
issue.setCustomFieldValue(customField, cfEpicValue)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
@Alejandro Suárez García we cannot make any defaults also , if we make dafault value then user will not fill the right value and technically there is no restriction if we place the default value.
I am trying the solution @Mark Markov gave , if that works good else i will remove the required restriction in field config and put it in the validator .
Abyakta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Abyakta Lenka sorry for triple posting, i'm not sure what happened :/
The problem with that behaviour is that if you have Epic Link preseted (by clicking "plus" simbol in the epic issue) it wont work. If you want to work both ways here is the code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def epicLink = getFieldById("customfield_10102")
def epicLinkId
if (epicLink.getFormValue()){
epicLinkId = epicLink.getFormValue().toString().replaceAll("key:", "")
} else {
epicLinkId = getFieldById(getFieldChanged()).getValue().toString().replaceAll("key:", "")
}
def epicIssue = issueManager.getIssueObject(epicLinkId)
def cf = customFieldManager.getCustomFieldObject(102090L)
def cfValue = epicIssue.getCustomFieldValue(cf) as Option
if (cfValue) {
getFieldById("customfield_102090").setFormValue(cfValue.optionId)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Abyakta Lenka
You can fill form value via Scriptrunner Behaviours and method setFormValue
getFieldById(getFieldChanged()).setFormValue(valuefromepic)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for answering
But i didnt get your point .
Should i go to Behaviours and add a new Behaviour ?
is this the only way ? i am little unfamiliar with Behaviour .
if you can explain that will help .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Mark Markov Why do you need to make that field required if you dont put it on the screen and pass the value in the postfunction?
Other solution is to make an option default in the customfield and set it required in Field Configuration. This way you dont need to put it on the screen and the script postfunction should work without problems.
If you need it, here is the Script Postfunction to copy the value from an epic. You should put it on the last position in postfunctions on create transition.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def epicLink = customFieldManager.getCustomFieldObject(10102L)
def epic = issue.getCustomFieldValue(epicLink) as Issue
def customField = customFieldManager.getCustomFieldObject(10110L) // Your CF
def cfEpicValue = epic.getCustomFieldValue(customField)
if (epic) {
issue.setCustomFieldValue(customField, cfEpicValue)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Abyakta Lenka
Yes you should add new behaviour, add mapping to your project and issue types.
Behaviuors can fill fields right on form depends on other fields. Here is example for your case:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
if (getActionName() == "Create Issue"){
def epicKey = getFieldById(getFieldChanged()).getValue() as String
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def customField = customFieldManager.getCustomFieldObject("customfield_102090")
Issue epicissue = issueManager.getIssueObject(epicKey.substring(4))
getFieldById("customfield_102090").setFormValue(epicissue.getCustomFieldValue(customField))
}
Let me explain what happens here.
First we find that we are on the Create Issue screen.
Then we get what we have in Epic Link field.
Declare customFieldManager and issueManager to work with customfield and issue objects.
Get our customField and issue object.
And last. Set value of customField on current from from Epic Issue.
That behaviour must be attached to Epic Link field:
go to behaviours -> your created behaviour and :
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the help . i learned a new thing and now i know where to use this and how to use this .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Abyakta Lenka,
This should work, add it to the Task Workflow create postfunction, in the last place.
P.D.: you should check that CustomField ID, I dont think it is right (too long).
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def epicLink = customFieldManager.getCustomFieldObject(10102L)
def epic = issue.getCustomFieldValue(epicLink) as Issue
def customField = customFieldManager.getCustomFieldObject(102090L)
def cfEpicValue = epic.getCustomFieldValue(customField)
if (epic) {
issue.setCustomFieldValue(customField, cfEpicValue)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alejandro Suárez García veo que controlas bastante, quisiera hacerte una pregunta referente a lo que habeis mencionado por aqui.
Yo trabajo en CLOUD, y me es complicado crear una story por groovy, tu sabrias hacerlo.
Realmente lo que necesito es que cada vez que creo una demanda se cree una story. He de hacerlo en una post function y no me acabo de aclarar.
Gracias
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register Now
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.