CustomFieldManager is not getting the custom field after modifying the custom field name using REST api in jira

一世执手 提交于 2019-12-11 13:19:07

问题


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:


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



来源:https://stackoverflow.com/questions/37131879/customfieldmanager-is-not-getting-the-custom-field-after-modifying-the-custom-fi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!