CustomFieldManager is not getting the custom field

2019-07-23 13:16发布

I'm changing the custom field name using the REST api in JIRA. It is changing the custom field name suceessfully. But when I tried to get the custom filed in the code, I'm getting null as the result.

String modByWhomCustomFieldName = pluginConfigService.getMUFCustomFieldName();
    System.out.println("+++++++++++++++++++In flagCustomField() modByWhomCustomFieldName is:"+modByWhomCustomFieldName);

    //CustomField modByWhomCustomField = cfManager.getCustomFieldObjectByName("Description Changed By");
    CustomField modByWhomCustomField = cfManager.getCustomFieldObjectByName(modByWhomCustomFieldName);
    if(modByWhomCustomField != null) {
        System.out.println("++++++++++++++ "+modByWhomCustomField.getDescription());
    }

In the above it is not entering into the if conditon.

Edited from here. Whenever user changed the description of an issue, I'm displaying that user. For this I have created one custom field of type "UserCFType" . It is displaying the user who modified the description. But for user admin, it is displaying admin(admin) . I just want "admin" only not "admin(admin)".

Object modByWhomCustomFieldOldValue = issue.getCustomFieldValue(modByWhomCustomField);
        Object modByWhomCustomFieldNewValue = user;
        System.out.println("+++++++++++++++++++In flagCustomField() current user is:"+modByWhomCustomFieldNewValue.toString());

        ModifiedValue<Object> modifVal2 = new ModifiedValue<>(modByWhomCustomFieldOldValue, modByWhomCustomFieldNewValue);
        modByWhomCustomField.updateValue(null, issue, modifVal2, changeHolder);

The above is the code for that.

1条回答
We Are One
2楼-- · 2019-07-23 13:54

try, getting the value. When you get the customfield object, you are getting the CF itself, not the value of that custom field at any issue. So, you get the custom field, and then the value of it for a specific issue:

cfManager.getCustomFieldObjectByName(modByWhomCustomFieldName).getValue(yourIssue)

**EDIT: For the name displaying problem, try using the getDisplayName() method on user object. Regards

查看更多
登录 后发表回答