I have in issues a field (type Select list) that I would like propagate to a sub task during it creation.
With Behaviour plugin, I can initialize the field (and offer the possibility to an user to update it).
I succeed to get the Parent custom field value with the following code:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
def issueid = getFieldById("parentIssueId").value;
def String NRD= "NRD"
if (issueid!=null){
//Recuperation de la demande parente à la sous-tache
def Issue parentIssue = ComponentManager.getInstance().getIssueManager().getIssueObject(Long.parseLong(issueid));
//Recuperation de la valeur du champ NRD sur la demande parente
def CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
def CustomField parentcustomField = customFieldManager.getCustomFieldObjectByName(NRD);
def Object parentnrd = parentIssue.getCustomFieldValue(parentcustomField);
But if I want initialize the sub task field, I need the custom field option Id:
FormField fillenrd=getFieldByName(NRD);
fillenrd.setFormValue("68931"); //where 68931 is the id of the selected value
I don't know how get the Id of the value from the object "parentnrd" defined above.
Please help....
Thank you.
Community moderators have prevented the ability to post new answers.
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.customfields.option.Option def String NRD= "NRD"; def FormField fillenrd = getFieldById(getFieldChanged()); if (fillenrd.getFormValue().equals("-1")) {//Issue: if the NRD field has a default value defined in the Field Configuration, the value is != "-1" def issueid = getFieldById("parentIssueId").value; ComponentManager componentManager = ComponentManager.getInstance(); //Recuperation de la demande parente à la sous-tache def Issue parentIssue = componentManager.getIssueManager().getIssueObject(Long.parseLong(issueid)); //Recuperation de la valeur du champ NRD sur la demande parente def CustomFieldManager customFieldManager = componentManager.getCustomFieldManager(); def CustomField parentcustomField = customFieldManager.getCustomFieldObjectByName(NRD); def Option parentnrd = (Option)parentIssue.getCustomFieldValue(parentcustomField); //Mise à jour du champ NRD sur la sous-tache fillenrd.setFormValue(parentnrd.getOptionId()); }
The code works fine except when the NRD has a defaut value defined in the configuration of the field... I would like the value of the sub task always initialize with the parent NRD (even if another default value is configured) and keep te possibility for user to update it during creation step....
if both field are select list type then try with this code
def Option parentnrd = (Option)parentIssue.getCustomFieldValue(parentcustomField); FormField fillenrd=getFieldByName(NRD); fillenrd.setFormValue(parentnrd.getId());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thank you. It works.
But each time, we update the field NRD, the value is set to its parent issue value. i have tried to add:
fillenrd.setReadOnly(false); without effect....
Any idea?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you mean you don't want to set if the field value is not empty? is it correct? if it is wrong can you explain little bit more pls!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
good question...
I have tried to add a test on the field value (if == null). But the field should have a default value. In this case, the NRD field isn't initialized...
On sub-task, the NRD field, should have been initialized with the parent NRD field. But I need keep the default value on this field for parent issues....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i think just you are copy field value from parent issue to sub task right? if yes then how it will change on parent issue ?
can you share your entaire code of this function?
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.