Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

JIRA Behaviour: Initialize a customfield value of a sub task in the Create screen

Céline M August 18, 2013

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.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Céline M August 19, 2013
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....

0 votes
RambanamP
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.
August 18, 2013

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());

Céline M August 18, 2013

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?

RambanamP
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.
August 18, 2013

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!

Céline M August 19, 2013

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....

RambanamP
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.
August 19, 2013

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?

TAGS
AUG Leaders

Atlassian Community Events