Forums

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

Values display in issue screen + issue search and not in edit screen of the current issue

Dan27
Contributor
June 21, 2018

Hello,

I wrote a code which copy from parent custom field- Select choice- the value, into the child issue custom field.

The code works pretty well, We can see the current value that copued into the chile custom field-Select choice (Pic 1)

Pic 1.PNG

 

 

We noticed that when we select 'Edit' screen, the value is "None", and when we came back to the issue screen, we saw the good value again. (Pic 2)

 

 

Pic 2.PNG

Please, I need your help, it's a little bit urgent..

 

My Code to aspecific issue:

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.security.groups.GroupManager;
import com.atlassian.jira.issue.IssueImpl;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.option.OptionsImpl
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
//Test
//def issueManager = ComponentAccessor.getIssueManager();
IssueManager issueManager = ComponentAccessor.getIssueManager();
def optionsManager = ComponentAccessor.getComponentOfType(OptionsManager.class);


//IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class);
Issue issue = issueManager.getIssueObject("WBL-46292");
def customFieldManager = ComponentAccessor.getCustomFieldManager();
//def issue = event.issue as MutableIssue

//Copy WBL Agile Team value to Development Team field

if (issue.getIssueType().name=='QVR') {
log.warn 1;
//Get Assigned QA Team value and WBL Agile Team value
def QAteam = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Assigned QA Team"));
def WBLteam = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("WBL Agile Team"));

//Get WBL Agile Team value and development value
CustomField wbl = customFieldManager.getCustomFieldObjectByName("WBL Agile Team");
CustomField development = customFieldManager.getCustomFieldObjectByName("Development Team");

//Get value= 'Unassigned Team'
def value = ComponentAccessor.optionsManager.getAllOptions()?.find { it.getValue() == 'Unassigned Team' };
def cFieldValue = issue.getCustomFieldValue(wbl);
//Cope WBL Agile Team value to Development Team

IssueChangeHolder changeHolder1 = new DefaultIssueChangeHolder();
development.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(development), WBLteam), changeHolder1);

//If Assigned QA Team = null, Put 'Unassigned Team' in WBL Agile Team
if (!QAteam) {
def wblValue = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("WBL Agile Team")
def cfConfig = wblValue.getRelevantConfig(issue)
def value2 = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == value
}

issue.setCustomFieldValue(wblValue, [value]);
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);
log.warn 2;
}
//If Assigned QA Team != null, Put Assigned QA Team value in 'WBL Agile Team'

else {
log.warn 3;
def wblValue = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("WBL Agile Team")
def cfConfig = wblValue.getRelevantConfig(issue)
def value2 = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == QAteam
}

issue.setCustomFieldValue(wblValue, [QAteam]);
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);

 

// apply changes to Jira -----------------------

def cFieldValue2 = issue.getCustomFieldValue(wbl);
log.warn cFieldValue2.toString();
log.warn QAteam;
}


def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService);
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
log.warn("Reindex issue ${issue.key} ${issue.id}");
issueIndexingService.reIndex(issueManager.getIssueObject(issue.id));
ImportUtils.setIndexIssues(wasIndexing);

}

 

1 answer

0 votes
Mark Markov
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.
June 21, 2018

Hello @Dan27

This is uncommon behavior, may be some problem with indexing.
Try to use issue.setCustomFieldValue() instead of updateValue()

// set field values -------------------------------
issue.setCustomFieldValue(singleline_field, "test 1")

// apply changes to Jira -----------------------
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

Also check this article about update fields in jira:

https://community.atlassian.com/t5/Agile-articles/Three-ways-to-update-an-issue-in-Jira-Java-Api/ba-p/736585 

Dan27
Contributor
June 21, 2018

Thanks @Mark Markov , who is is user ? how can I identify it?

Mark Markov
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.
June 21, 2018

Depens on what you need.

Current user you can get like this

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Dan27
Contributor
June 21, 2018

last question, The code didn't recognize the line: 

ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

Can you send me the imports ? 

Mark Markov
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.
June 21, 2018

I think, you only missing

import com.atlassian.jira.event.type.EventDispatchOption;
Dan27
Contributor
June 21, 2018

Thanks!

It's not working, still display the correct value in the issue screen , and "None" in the Edit screen..

More suggestions ?

Mark Markov
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.
June 21, 2018

May be there are some behaviours on that field? That make empty it.

Dan27
Contributor
June 21, 2018

No we din't have...

Dan27
Contributor
June 21, 2018

@Mark Markov I just want to say them both are single select field.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events