Forums

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

How can i add custom filed value while creating a new jira issue from java API

saurabh choudhary
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 30, 2018

I have a custom field PK ID created in jira project(APT). i want to create a new issue of type story and set PK ID field value while creating the issue.

I am trying following code:-

IssueInputBuilder issueBuilder = new IssueInputBuilder("APT",10002L,"XYZ");
issueBuilder.setIssueTypeId(10001L);
//issueBuilder.setFieldValue("PK ID",new String("Hello"));
//issueBuilder.setFieldValue("customField_10013",new String("Hello"));
URI jiraServiceUri = new URI("<removed url>" + ":" + "8080");
JiraRestClient clientUtil = (JiraRestClient) new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(jiraServiceUri,"388961", "Jira@1234");
clientUtil.getIssueClient().createIssue(issueBuilder.build());

 

Issue not getting created when i use issueBuilder.setFieldValue() method.

How can i set value for PK ID custom filed while creating issue

 

1 answer

0 votes
Danyal Iqbal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2018

What response do you get from jira? compare the json your are sending to jira with the json of an existing ticket in this project.

i would do something along the lines of:

  Collection<FieldInput> issueProps = new ArrayList<FieldInput>();
    IssueRestClient issueClient = jiraConnection.getIssueClient();
    List<JiraField> fields = getRequiredFields();

    for (JiraField field : fields) {
        //System.err.println(field.getFieldId().trim());
      String[] args = new String[] { field.getFieldId(), ""};



      if ("PK ID".equalsIgnoreCase(field.getFieldId().trim())) {
        args = new String[] { field.getFieldId(), "Hotline Ticket"};
      }
      if (args[1] != null && args[1].trim().length() > 0) {
        field.setValue(args[1]);
//        System.err.println(field.getValue());
        issueProps.add(field.asFieldInput());
      }
}
  public List<JiraField> getRequiredFields() {
    JiraSortedFieldCache fieldCache = new JiraSortedFieldCache();
    fieldCache.loadFieldsFromFile();
    return fieldCache.getCachedFields();
  }

Suggest an answer

Log in or Sign up to answer