Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Populating Text field value in Select list custom field on issue creation using behaviour

suchitk May 12, 2016

Hi,

I have two custom field named as Test (Single line text field) and Demo(Select list custom field).

I need to populate Test custom field value in Demo custom field value and set the Test custom field value as default value in Demo custom field.

Below is the code which is populating the Test (Single line text field) value in Demo(Select list custom field) .But when we check the Demo(Select list custom field) options on edit issue screen it not gets update their for first time.

When we click on cancel option of issue and again edit that issue then the value gets updated their in Demo(Select list custom field).

 

//Populating select list custom field dynamically in jira
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
import com.atlassian.jira.issue.customfields.option.Option;
import com.atlassian.jira.issue.customfields.option.Options;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.index.IssueIndexManager;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.ModifiedValue;
import java.util.ArrayList;

Object id = getFieldById("id");
MutableIssue issueObject = ComponentAccessor.getIssueManager().getIssueObject(Long.parseLong(id.value));

Issue issue=ComponentAccessor.getIssueManager().getIssueObject(Long.parseLong(id.value));
def optionsManager = ComponentAccessor.getOptionsManager()
def fieldManager = ComponentAccessor.getCustomFieldManager()
def envFld = fieldManager.getCustomFieldObjectByName("Demo")
def envFld1 = fieldManager.getCustomFieldObjectByName("Test ")
def envs = issueObject.getCustomFieldValue(envFld1);
def fieldConfig = envFld.getRelevantConfig(getIssueContext())
def newSeqId = 0

def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
Options opt=optionsManager.getOptions(fieldConfig)
log.error("---- All Option value are----"+opt)
List<String> comp_name=new ArrayList<String>(opt);
def count = 0;
for(String a :comp_name){  
    if(a.equalsIgnoreCase(envs)){
        
       count = 1;
        log.error("-------count of value is 1 ........Value already present--"+count)
        }
}
if(count == 0){
  log.error("-------count of value is 0 ........Value not  present--"+count)   
def option = optionsManager.createOption(fieldConfig, null, newSeqId++, envs)
log.error("@@@@@@@@@@@@ Adding Test Value  ###########"+option)
log.error("@@@@@@@@@@@@ Added Test Value  ###########"+issueInputParameters.addCustomFieldValue(envFld.idAsLong, option.optionId.toString()))
    
}

Please suggest us how to do this.

Also please suggest how to set the default value in Demo(Select list custom field) programmatically.

Thanks in advance for your help.

Thanks and Regards,

Suchit R Kharatmol.

 

1 answer

0 votes
Ranganath HV Gowda
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.
September 28, 2016

You can give a look on this link https://confluence.atlassian.com/jirakb/how-to-display-a-field-based-on-another-field-s-selection-649921383.html

It will help you to design your custom field values

Suggest an answer

Log in or Sign up to answer