Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse a parameter from custom field #607

Open
JinoArch opened this issue Jan 23, 2023 · 1 comment
Open

Parse a parameter from custom field #607

JinoArch opened this issue Jan 23, 2023 · 1 comment

Comments

@JinoArch
Copy link

I am using jql search for getting jira issues using the same golang client. And I am trying to get sprint name attached to each issues. But it looks like the sprint field is a custom one.

As per json payload like below (I used "$JIRA_URL/rest/api/2/issue/JIN-3047" to get this payload)

The value in "name" is what I need

"customfield_10005": [
      {
        "id": 6942,
        "name": "JIN Dev 2023: Jan 16 - Jan 27",
        "state": "active",
        "boardId": 618,
        "goal": "",
        "startDate": "2023-01-16T16:12:06.752Z",
        "endDate": "2023-01-27T17:12:00.000Z"
      }
    ],

Wonder how can I parse this using Golang client?

  • go-jira version: v1.16.0 (latest release available in this repo)
  • go version: 1.19.X
  • Jira Type: cloud
@felixgeelhaar
Copy link

felixgeelhaar commented Oct 11, 2023

Hey @JinoArch,
what I did to parse the object of the customfield is using a library called mapstructure.
So my code looks like:

type CustomFieldResponse struct {
	ID string
	Self string
	Value string
}

func RetrieveCustomFieldValue(id string, customfieldMap tcontainer.MarshalMap) (CustomFieldResponse) {
	var mapped CustomFieldResponse
	result, _ := customfieldMap.Value(id)
	mapstructure.Decode(result, &mapped)

	return mapped
}

And then I can extract the Value of the customfield by providing the customfield id and all customfields:

...
someValueOfCustomField := RetrieveCustomFieldValue("customfield_11056", customFields)
...

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants