I'm writting an application which needs to be able to create tickets using the RESTful API. I'm using the java rest client (version 1.0) to do this. When creating issues, I need to populate two custom fields. At the moment I'm using the custom field id customfield_10021 for example. Am I am able to set the field value by the actual name of the field, or look up the field id by its name in some way. I'm not eager to leave the custom field ids hard coded as I imagine they'll be different on different JIRA instances (we actually have 3 running, a local develoment copy, a test instance and a production instance).
Hi, here's a sample code for getting field id by name for a project that should help you write your own function:
private String getFieldId(String projectKey, String fieldName) { GetCreateIssueMetadataOptions options = new GetCreateIssueMetadataOptionsBuilder() .withProjectKeys(projectKey).withExpandedIssueTypesFields().build(); Iterable<CimProject> metsdata = restClient.getIssueClient().getCreateIssueMetadata(options) .claim(); CimProject cim = metsdata.iterator().next(); for (CimFieldInfo info : cim.getIssueTypes().iterator().next().getFields().values()) { if(info.getName().equals(fieldName)) { return info.getId(); } } return null; }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Would you mark my answer as accepted ?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Works, Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.