go-jira icon indicating copy to clipboard operation
go-jira copied to clipboard

Custom fields not being written, and creating issues returns an incorrect *jira.Issue with nil fields

Open modernplumbing opened this issue 3 years ago • 4 comments

Describe the bug

I'm on Jira Cloud trying to create new issues with custom fields. I have the following code, and the custom field is not getting written. Additionally, the createdIssue has a nil value for Fields, even though in the UI, the other specified fields minus the custom fields are getting written.

		newIssue := jira.Issue{
			Fields: &jira.IssueFields{
				Summary:     oldIssue.Fields.Summary,
				Description: oldIssue.Fields.Description,
				Project: jira.Project{
					Key: "NEWBOARD",
				},
				Type: jira.IssueType{
					Name: "NEWTYPE",
				},
				Assignee: oldIssue.Fields.Assignee,
				Duedate:  oldIssue.Fields.Duedate,
				Unknowns: tcontainer.MarshalMap{
					"customfield_11228": 1386,
				},
			},
		}

createdIssue, resp, err := c.JClient.Issue.Create(&newIssue)

To Reproduce

Adding

	"customfield_11228": 1386,
},

to https://sourcegraph.com/github.com/andygrunwald/go-jira/-/blob/examples/createwithcustomfields/main.go should be reproduceable.

Expected behavior

I expect this custom field to be written and visible in the UI. I also expect the returned *jira.Issue (createdIssue in the above example) to reflect the issue that was created, i.e. not having a nil value for the Fields.

Your Environment

Jira Cloud github.com/andygrunwald/go-jira v1.13.0 github.com/trivago/tgo v1.0.7

Additional context

I am migrating tickets from one board to another. Because of the custom fields, I need to create new issues in the new project, but I am blocked on being unable to write the custom fields.

modernplumbing avatar Jun 10 '21 05:06 modernplumbing

Hi! Thank you for taking the time to create your first issue! Really cool to see you here for the first time. Please give us a bit of time to review it.

github-actions[bot] avatar Jun 10 '21 05:06 github-actions[bot]

Hey @modernplumbing, thanks for the issue. I am curious, why do you close it already? Were you able to find a solution? If yes, would you mind sharing it with the community?

andygrunwald avatar Jun 12 '21 07:06 andygrunwald

The functionality itself seems to be working, the pattern as documented doesn't quite work, though. This should work instead:

unknown := tcontainer.NewMarshalMap()
//setting typical text/string field's value
unknown.Set("customfield_11801", "mystringvalue")
customfield2 := tcontainer.NewMarshalMap()
customfield2.Set("value", "MatchingIdsValue")
unknown.Set("customfield_11502", customfield2)

&jira.Issue{
		Fields: &jira.IssueFields{
			Unknowns: unknown,
		},
	}

danekantner avatar Aug 11 '21 18:08 danekantner

To add to the above, to set a labels field instead it's the same syntax as if it were just a string except you provide an array:

unknown.Set("customfield_11503", []string{"label1", "label2", "label3"})

danekantner avatar Sep 28 '21 20:09 danekantner

Hey,

I am very sorry that this issue has been open for a long time with no final solution. We work on this project in our spare time, and sometimes, other priorities take over. This is the typical open source dilemma.

However, there is news: We are kicking off v2 of this library 🚀

To provide visibility, we created the Road to v2 Milestone and calling for your feedback in https://github.com/andygrunwald/go-jira/issues/489

The development will take some time; however, I hope you can benefit from the changes. If you seek priority development for your issue + you like to sponsor it, please contact me.

What does this mean for my issue?

We will work on this issue indirectly. This means that during the development phase, we aim to tackle it. Maybe in a different way like it is currently handled. Please understand that this will take a while because we are running this in our spare time.

Final words

Thanks for using this library. If there is anything else you would like to tell us, let us know!

andygrunwald avatar Aug 21 '22 14:08 andygrunwald