1

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.

user2636874
  • 889
  • 4
  • 15
  • 36

1 Answers1

0

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

Oldskultxo
  • 945
  • 8
  • 19
  • Ok. Have you declared the CfManager? and are you sure that the issue has a value for that custom field? and the name of the customField is exactly the same as the correct one(Case sensitive)? – Oldskultxo May 10 '16 at 09:11
  • Yes, I've declared the custom field manager and also issue has the value for that field. – user2636874 May 10 '16 at 09:14
  • So, could you post the error traze? maybe you can wrap your code with a try{}catch(Exception e){System.out.println(e.getStackTrace())} – Oldskultxo May 10 '16 at 09:20
  • Hey thanks for your help. I came to know that Jira Administrator have to modify the existing custom field name to the new name i.e. the name which is modified using the rest api. – user2636874 May 10 '16 at 09:42
  • So it is null because the admin has not changed the name? lol you could get crazy ! lol – Oldskultxo May 10 '16 at 09:52
  • Hey, I've one more doubt. Can you tell me. My custom field is of type UserCFType. Whenever I'm trying to display the custom field, it is populating like admin(admin). Is there any way to get only "admin" instead of admin(admin). Below is the code to populate the custom field value. – user2636874 May 10 '16 at 10:21
  • Sure,i can try. Wich doubt? – Oldskultxo May 10 '16 at 10:23
  • This is the code to popuate the value. Object modByWhomCustomFieldOldValue = issue.getCustomFieldValue(modByWhomCustomField); Object modByWhomCustomFieldNewValue = user; System.out.println("+++++++++++++++++++In flagCustomField() current user is:"+modByWhomCustomFieldNewValue.toString()); ModifiedValue modifVal2 = new ModifiedValue<>(modByWhomCustomFieldOldValue, modByWhomCustomFieldNewValue); modByWhomCustomField.updateValue(null, issue, modifVal2, changeHolder); – user2636874 May 10 '16 at 10:28
  • wow, i cant understand your new problem. Could you edit the question? – Oldskultxo May 10 '16 at 10:33