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