About

scottizu

Bio:

View complete profile

 

4 thoughts on “About

  1. Hi Scottizu, I found your tutorials extremely useful for my project. But I still have an issue I was hoping you could answer. I want to get the list of fields in a resolved and closed issue. Any idea how i can get just the list of field names ?

    • Note. The curl calls below were made from the Git Bash command prompt. As such, you will see the urls containing \& to add query parameters to the url. Compare these two urls:
      URL – https://my.jira.com/rest/api/2/issue/createmeta?projectKeys=MYPROJECT&issuetypeIds=1&expand=projects.issuetypes.fields
      Modified URL for Git Bash CURL command – https://my.jira.com/rest/api/2/issue/createmeta?projectKeys=MYPROJECT\&issuetypeIds=1\&expand=projects.issuetypes.fields

      To get the existing fields and values of an issue, you will need the issueID or issueKey. With these, you may make the following calls.

      curl -k https://my.jira.com/rest/api/2/issue/1111111 -u scott:password
      curl -k https://my.jira.com/rest/api/2/issue/MYPROJECT-111 -u scott:password

      curl -k https://${jiraServerDomain}/rest/api/2/issue/${issueID} -u ${username}:${password}
      curl -k https://${jiraServerDomain}/rest/api/2/issue/${issueKey} -u ${username}:${password}

      Search for the “project” key in the response JSON. The value of the “project” key will be a JSON object that has the “key” key. The value of the “key” key is the projectKey.

      Example:
      …”project”:{“self”:”https://my.jira.com/rest/api/2/project/11111″,”id”:”11111″,”key”:”MYPROJECT”,”name”:”My Project”,…

      Search for the “issueType” key in the response JSON. The value of the “issueType” key will be a JSON object that has the “id” key. The value of the “id” key is the issueTypeID.

      Example:
      …”issuetype”:{“self”:”https://my.jira.com/rest/api/2/issuetype/1″,”id”:”1″…

      Unfortunately, the fieldID is returned from the query above. This might be something cryptic like “customfield_11111”. Fortunately, the allowedValueID and allowedValueValue is returned.

      Example:
      …”customfield_1111″:{“self”:”https://my.jira.com/rest/api/2/customFieldOption/22222″,”value”:”Working”,”id”:”22222″}…

      In order to find the fieldName associated with the fieldID, you will have to use the projectKey and issueTypeID and run this query.

      curl -k https://my.jira.com/rest/api/2/issue/createmeta?projectKeys=MYPROJECT\&issuetypeIds=1\&expand=projects.issuetypes.fields -u scott:password

      curl -k https://${jiraServerDomain}/rest/api/2/issue/createmeta?projectKeys=${projectKey}\&issuetypeIds=${issueTypeID}\&expand=projects.issuetypes.fields -u ${username}:${password}

      Search for the fieldID and you will have access to the fieldName and an array of allowedValues (which each have an allowedValueID and allowedValueValue).

      …”customfield_1111″:{“required”:false,”schema”:{“type”:”array”,”items”:”string”,”custom”:”com.atlassian.jira.plugin.system.customfieldtypes:multiselect”,”customId”:1111},”name”:”My Custom Field Name”,”hasDefaultValue”:false,”operations”:[“add”,”set”,”remove”],”allowedValues”:[{“self”:”https://my.jira.com/rest/api/2/customFieldOption/22222″,”value”:”Working”,”id”:”22222″},{“self”:”https://my.jira.com/rest/api/2/customFieldOption/33333″,”value”:”Not Working”,”id”:”33333″},{“self”:”https://my.jira.com/rest/api/2/customFieldOption/44444″,”value”:”Almost Working”,”id”:”44444″}}]}…

      • Issue issue = Client.getIssueClient().getIssue(“issueKey”).claim();
        String json = new Gson().toJson(issue.getFields());
        JSONArray array = new JSONArray(json);
        System.out.println(array);
        ArrayList list = new ArrayList();
        for(int i = 0; i < array.length() ; i++){
        if(array.getJSONObject(i).has("value")){

        list.add(array.getJSONObject(i).get("name").toString());

        }
        }

        I am currently using this to get the list, but some of the fields do not match with the fields present in the UI. I got what you have mentioned in the post but I am not able to implement the same in java. Any way I can achieve that ?

        Thanks !

      • Issue issue = jiraRestClient.getIssueClient().getIssue(“issueKey”).claim();
        Iterable issueFields = issue.getFields();
        for(IssueField issueField: issueFields) {
        System.out.println(“ID:”+issueField.getId());
        System.out.println(“Name:”+issueField.getName());
        System.out.println(“Value:”+issueField.getValue());
        }

        This will print out all the fields.

        Example:
        ID:customfield_11111
        Name:A Custom Field
        Value:{“self”:”https:\/\/my.jira.com\/rest\/api\/2\/customFieldOption\/22222″,”value”:”My Value”,”id”:”22222″}

        In the UI, you would probably see “A Custom Field” and “My Value”.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s