
๐งฉExtract customfields from issue(s)
Introduction
In Jira Cloud, custom fields are managed in a way that allows for flexibility and dynamic creation. Each new custom field that you create within a Jira Cloud instance is assigned a unique ID. This ID is used to identify and manage the custom field's configuration and data within the Jira system.
In this particular case, the library contains multiples helpers method will help you to extract the customfield information by type using the response buffer.
Extract from a single issue
The following methods can be used to extract the customfield information from one issue.
ParseMultiSelectCustomField
This method parses a multi-select custom field from the given buffer data associated with the specified custom field ID and returns a slice of pointers to CustomFieldContextOptionSchema
structs.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
options, err := models.ParseMultiSelectCustomField(response.Bytes, "customfield_10046")
if err != nil {
log.Fatal(err)
}
for _, option := range options {
fmt.Println(option.ID, option.Value)
}
ParseSelectCustomField
ParseSelectCustomField parses a select custom field from the given buffer data associated with the specified custom field ID and returns a CustomFieldContextOptionScheme struct
_, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
option, err := models.ParseSelectCustomField(response.Bytes, "customfield_10047")
if err != nil {
log.Fatal(err)
}
fmt.Println(option.ID, option.Value)
ParseCascadingSelectCustomField
This method parses a cascading custom field from the given buffer data associated with the specified custom field ID and returns a CascadingSelectScheme struct pointer.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
cascading, err := models.ParseCascadingSelectCustomField(response.Bytes, "customfield_10045")
if err != nil {
log.Fatal(err)
}
fmt.Println(cascading.Value, cascading.Child.Value)
ParseDatePickerCustomField
ParseDatePickerCustomField parses the datepicker customfield from the given buffer data associated with the specified custom field ID and returns a struct time.Time value
_, response, err := client.Issue.Get(context.Background(), "KP-24", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
datePicker, err := models.ParseDatePickerCustomField(response.Bytes, "customfield_10040")
if err != nil {
log.Fatal(err)
}
fmt.Println(datePicker.String())
ParseDateTimeCustomField
ParseDateTimeCustomField parses the datetime customfield from the given buffer data associated with the specified custom field ID and returns a struct time.Time value.
_, response, err := client.Issue.Get(context.Background(), "KP-24", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
datePicker, err := models.ParseDateTimeCustomField(response.Bytes, "customfield_10041")
if err != nil {
log.Fatal(err)
}
fmt.Println(datePicker.String())
ParseMultiUserPickerCustomField
This method parses a group-picker custom field from the given buffer data associated with the specified custom field ID and returns a slice of pointers to UserDetailScheme structs.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
users, err := models.ParseMultiUserPickerCustomField(response.Bytes, "customfield_10055")
if err != nil {
log.Fatal(err)
}
for _, user := range users {
fmt.Println(user.EmailAddress, user.AccountID)
}
ParseMultiGroupPickerCustomField
This method parses a group-picker custom field from the given buffer data associated with the specified custom field ID and returns a slice of pointers to GroupDetailScheme structs.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
groups, err := models.ParseMultiGroupPickerCustomField(response.Bytes, "customfield_10052")
if err != nil {
log.Fatal(err)
}
for _, group := range groups {
fmt.Println(group.Name)
}
ParseFloatCustomField
ParseFloatCustomField parses a float custom field from the given buffer data associated with the specified custom field ID and returns string.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
number, err := models.ParseFloatCustomField(response.Bytes, "customfield_10043")
if err != nil {
log.Fatal(err)
}
fmt.Println(number)
ParseSprintCustomField
ParseSprintCustomField parses a sprints custom field from the given buffer data associated with the specified custom field ID and returns a slice of the SprintDetailScheme struct.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
sprints, err := models.ParseSprintCustomField(response.Bytes, "customfield_10020")
if err != nil {
log.Fatal(err)
}
for _, sprint := range sprints {
fmt.Println(sprint.ID)
}
ParseLabelCustomField
ParseLabelCustomField parses a textfield slice custom field from the given buffer data associated with the specified custom field ID and returns string slice.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
labels, err := models.ParseLabelCustomField(response.Bytes, "customfield_10042")
if err != nil {
log.Fatal(err)
}
for _, label := range labels {
fmt.Println(label)
}
ParseMultiVersionCustomField
ParseMultiVersionCustomField parses a version-picker custom field from the given buffer data associated with the specified custom field ID and returns a slice of pointers to VersionDetailScheme structs.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
versions, err := models.ParseMultiVersionCustomField(response.Bytes, "customfield_10067")
if err != nil {
log.Fatal(err)
}
for _, version := range versions {
fmt.Println(version.ID, version.Name, version.Description)
}
ParseUserPickerCustomField
ParseUserPickerCustomField parses a user custom field from the given buffer data associated with the specified custom field ID and returns a struct of UserDetailScheme.
_, response, err := client.Issue.Get(context.Background(), "KP-24", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
user, err := models.ParseUserPickerCustomField(response.Bytes, "customfield_10051")
if err != nil {
log.Fatal(err)
}
fmt.Println(user.EmailAddress)
fmt.Println(user.DisplayName)
fmt.Println(user.AccountID)
fmt.Println(user.AccountType)
ParseAssetCustomField
ParseAssetCustomField parses the Jira assets elements from the given buffer data associated with the specified custom field ID and returns a struct CustomFieldAssetScheme slice.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
assets, err := models.ParseAssetCustomField(response.Bytes, "customfield_10068")
if err != nil {
log.Fatal(err)
}
for _, asset := range assets {
fmt.Println(asset.Id, asset.WorkspaceId, asset.ObjectId)
}
ParseStringCustomField
ParseStringCustomField parses a textfield custom field from the given buffer data associated with the specified custom field ID and returns string.
_, response, err := client.Issue.Get(context.Background(), "KP-24", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
textField, err := models.ParseStringCustomField(response.Bytes, "customfield_10049")
if err != nil {
log.Fatal(err)
}
fmt.Println(textField)
Extract from multiple issues
If you want to extract the customfield values from a buffer of issues, you can use the following methods, it returns a map where the key is the issue key and the value is the customfield values parsed
ParseMultiSelectCustomFields
ParseMultiSelectCustomFields extracts and parses multi-select custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of CustomFieldContextOptionScheme structs, representing the parsed multi-select custom field values.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10046"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
multiSelectOptions, err := models.ParseMultiSelectCustomFields(response.Bytes, "customfield_10046")
if err != nil {
log.Fatal(err)
}
for issue, options := range multiSelectOptions {
for _, option := range options {
fmt.Println(issue, option.ID, option.Value)
}
}
ParseSelectCustomFields
ParseSelectCustomFields extracts and parses select custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a CustomFieldContextOptionScheme struct, representing the parsed select custom field value.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10047"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseSelectCustomFields(response.Bytes, "customfield_10047")
if err != nil {
log.Fatal(err)
}
for issue, option := range customfields {
fmt.Println(issue, option.ID, option.Value)
}
ParseCascadingCustomFields
ParseCascadingCustomFields extracts and parses a cascading custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a CascadingSelectScheme struct pointer, representing the parsed cascading custom field value.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10045"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseCascadingCustomFields(response.Bytes, "customfield_10045")
if err != nil {
log.Fatal(err)
}
for issue, value := range customfields {
fmt.Println(issue, value.Value, value.Child.Value)
}
ParseMultiUserPickerCustomFields
ParseMultiUserPickerCustomFields extracts and parses a user picker custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of UserDetailScheme structs, representing the parsed multi-select custom field values.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10055"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseMultiUserPickerCustomFields(response.Bytes, "customfield_10055")
if err != nil {
log.Fatal(err)
}
for issue, users := range customfields {
for _, user := range users {
fmt.Println(issue, user.AccountID, user.DisplayName)
}
}
ParseDatePickerCustomFields
ParseDatePickerCustomFields extracts and parses the datepicker customfield data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a time.Time value, representing the parsed datepicker values with the Jira issues.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10040"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseDatePickerCustomFields(response.Bytes, "customfield_10040")
if err != nil {
log.Fatal(err)
}
for issue, datepicker := range customfields {
fmt.Println(issue, datepicker.String())
}
ParseDateTimeCustomFields
ParseDateTimeCustomFields extracts and parses the datetime customfield data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a time.Time value, representing the parsed datetime values with the Jira issues.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10041"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseDateTimeCustomFields(response.Bytes, "customfield_10041")
if err != nil {
log.Fatal(err)
}
for issue, datetime := range customfields {
fmt.Println(issue, datetime.String())
}
ParseMultiGroupPickerCustomFields
ParseMultiGroupPickerCustomFields extracts and parses a group picker custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of GroupDetailScheme structs, representing the parsed multi-group custom field values.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10052"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseMultiGroupPickerCustomFields(response.Bytes, "customfield_10052")
if err != nil {
log.Fatal(err)
}
for issue, groups := range customfields {
for _, group := range groups {
fmt.Println(issue, group.Name, group.GroupID)
}
}
ParseFloatCustomFields
ParseFloatCustomFields extracts and parses the float customfield information from multiple issues using a bytes.Buffer.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a string representing the parsed float64 customfield value.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10043"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseFloatCustomFields(response.Bytes, "customfield_10043")
if err != nil {
log.Fatal(err)
}
for issue, number := range customfields {
fmt.Println(issue, number)
}
ParseStringCustomFields
ParseStringCustomFields extracts and parses the textfield customfield information from multiple issues using a bytes.Buffer.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a string representing the parsed textfield customfield value.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10049"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseStringCustomFields(response.Bytes, "customfield_10049")
if err != nil {
log.Fatal(err)
}
for issue, textField := range customfields {
fmt.Println(issue, textField)
}
ParseUserPickerCustomFields
ParseUserPickerCustomFields extracts and parses a user custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a UserDetailScheme struct pointer ,representing the parsed user custom field value.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10051"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseUserPickerCustomFields(response.Bytes, "customfield_10051")
if err != nil {
log.Fatal(err)
}
for issue, user := range customfields {
fmt.Println(issue, user.AccountID)
}
ParseSprintCustomFields
ParseSprintCustomFields extracts and parses sprint custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of SprintDetailScheme structs, representing the parsed sprint custom field values.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10020"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseSprintCustomFields(response.Bytes, "customfield_10020")
if err != nil {
log.Fatal(err)
}
for issue, sprints := range customfields {
for _, sprint := range sprints {
fmt.Println(issue, sprint.Name, sprint.ID, sprint.BoardID, sprint.State)
}
}
ParseLabelCustomFields
ParseLabelCustomFields extracts and parses the label customfield information from multiple issues using a bytes.Buffer.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a string slice representing the parsed label customfield value.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10042"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseLabelCustomFields(response.Bytes, "customfield_10042")
if err != nil {
log.Fatal(err)
}
for issue, labels := range customfields {
fmt.Println(issue, labels)
}
ParseMultiVersionCustomFields
ParseMultiVersionCustomFields extracts and parses a version picker custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of VersionDetailScheme structs, representing the parsed multi-version custom field values.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10067"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseMultiVersionCustomFields(response.Bytes, "customfield_10067")
if err != nil {
log.Fatal(err)
}
for issue, versions := range customfields {
for _, version := range versions {
fmt.Println(issue, version.Name, version.ID)
}
}
ParseAssetCustomFields
ParseAssetCustomFields extracts and parses jira assets customfield data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of CustomFieldAssetScheme structs, representing the parsed assets associated with a Jira issues.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10072"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseAssetCustomFields(response.Bytes, "customfield_10072")
if err != nil {
log.Fatal(err)
}
for issue, assets := range customfields {
for _, asset := range assets {
fmt.Println(issue, asset.Id, asset.WorkspaceId, asset.ObjectId)
}
}
Last updated
Was this helpful?