Forums

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

Problems when I use getCustomFieldObjectByName [jython]

Txus
Community Champion
July 19, 2018 edited

Hi.

I have several problems with the addon "Jira Scripting Suite" of Jira.

When I use the method "getCustomFieldObjectByName" to get one CustomField, I get the None result, but the CustomField exist. 

from com.atlassian.jira import ComponentManager;
from com.atlassian.jira.component import ComponentAccessor;
from com.atlassian.jira.issue import CustomFieldManager;
from com.atlassian.jira.issue.fields import CustomField;
from com.atlassian.jira.user.preferences import PreferenceKeys;

customFieldManager = ComponentAccessor.getCustomFieldManager();
issueManager = ComponentAccessor.getIssueManager();
userPreferencesManager = ComponentAccessor.getUserPreferencesManager();

user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
extendedPreferences = userPreferencesManager.getExtendedPreferences(user);

language = ComponentAccessor.getJiraAuthenticationContext().getI18nHelper().getLocale().getLanguage();

# *** CF SCREEN CREATE ***
dataOwner_CREATECF = customFieldManager.getCustomFieldObjectByName("EDHES_Data owner");
dataOwnerGroupsSelect_CREATECF = customFieldManager.getCustomFieldObjectByName("EDHES_Data owner groups select");
log.info("***** dataOwnerCF: " + str(dataOwner_CREATECF) + " *****");
log.info("***** dataOwnerGroupsSelectCF: " + str(dataOwnerGroupsSelect_CREATECF) + " *****");

# *** CFV VALUE SCREEN ***
dataOwner_VALUE = issue.getCustomFieldValue(dataOwner_CREATECF);
dataOwnerGroupsSelect_VALUE = issue.getCustomFieldValue(dataOwnerGroupsSelect_CREATECF);

# **** VALUE ON SCREEN ***
log.info("***** dataOwner: " + unicode(dataOwner_VALUE, 'utf-8') + " *****");
log.info("***** dataOwnerGroupsSelect: " + unicode(dataOwnerGroupsSelect_VALUE, 'utf-8') + " *****");

if ((dataOwner_VALUE != None) or (dataOwnerGroupsSelect_VALUE != None)):
result = True;
else:
if ((dataOwner_VALUE == None) and (dataOwnerGroupsSelect_VALUE == None)):
result = False;
if (language == 'es'):
description = "Debe introducir uno de los siguientes campos: " + dataOwner_CREATECF.getFieldName() + " o " + dataOwnerGroupsSelect_CREATECF.getFieldName() + ".";
else:
description = "Must enter either " + dataOwner_CREATECF.getFieldName() + " or " + dataOwnerGroupsSelect_CREATECF.getFieldName() + ".";
else:
result = True;

This code is a screen validator to check if one customfield or another is not empty.

But when use getCustomFieldObjectByName with the CustomFieldManager the customfield is None.

I resolved this problem several time with a reindex of the Jira's instance, and the background reindex taked 12 hours.

Any idea to resolve this problem definitely???

 

Thanks for our time!!!

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events