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

Documentation for custom jira fields

Open pH-T opened this issue 4 years ago • 14 comments

Hi!

First: thanks for your work here! Its nice to have a Jira API impl. in Go!

I stumbled upon the Unknowns struct field of IssueFields and thus I think it should be possible (?) to add custom Jira fields - but how? Can you provide an example?

Thanks, pH-T

pH-T avatar Feb 10 '21 09:02 pH-T

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 Feb 10 '21 09:02 github-actions[bot]

Hello @pH-T , do you mean how to retrieve them? If so, please have a look to issue_test.go (line 776) https://github.com/andygrunwald/go-jira/blob/master/issue_test.go here you can check how to retrieve and work with custom fields and just below, with complex custom fields

If you are talking about a different opertation please explain and I will try to help you

Best.

manuelbcd avatar Feb 10 '21 18:02 manuelbcd

Thanks for your fast reply!

Sorry, I was not precise enough... I was wondering how I would create an issue with custom fields.

Should something like this work?

...
    u := tcontainer.NewMarshalMap()
    u["customField1"] = "customValue"

    i := jira.Issue{
        Fields: &jira.IssueFields{
            Description: "Test Issue from Golang",
            Type: jira.IssueType{
                Name: "Task",
            },
            Project: jira.Project{
                Key: "TEST",
            },
            Summary:  "Test-Sum",
            Unknowns: u,
        },
    }

    client.Issue.Create(&i)
    ...

I was not able to get this code snipped to run successfully, but this might be because of my local Jira-Testing-Instance...

pH-T avatar Feb 10 '21 20:02 pH-T

Yes, I think that is the way, let me bring you some examples from other issues

(Source https://github.com/andygrunwald/go-jira/issues/257#issuecomment-595637698 )

custome["customfield_10209"] = map[string]string{"value": assessment}

i := jira.Issue{
	Fields: &jira.IssueFields{
		Assignee: &jira.User{
			Name: jira_user,
		},
		Description: utf8toASCII(description),
		Type: jira.IssueType{
			ID: "10300",
		},
		Project: jira.Project{
			ID: "10308",
		},
		Summary: utf8toASCII(summary),
		Unknowns: custome,
	},
}

Also have a look to this post and its resolution: https://github.com/andygrunwald/go-jira/issues/117

Pls let us know if that helps

manuelbcd avatar Feb 11 '21 09:02 manuelbcd

Thank you, that helps! So I was on the right track... :)

pH-T avatar Feb 11 '21 10:02 pH-T

Hey @pH-T and @manuelbcd Thanks for stepping in and solving this issue.

Would one of you mind to create a PR and create a proper example into the documentation/readme/example unit test? This would be great.

andygrunwald avatar Feb 11 '21 13:02 andygrunwald

Hello @andygrunwald, playing with the project to implement this new test I have noticed that the CreateIssue example (https://github.com/andygrunwald/go-jira/blob/master/examples/create/main.go) is not working with Jira Cloud (equivalent to jira software 8.15.x right now).

The creation method works properly but the return body does not include the "Summary" field so at the end of the example you will get a panic break because Summary var is not initialized.

I'm wondering how to enrich this example, since it is workign with older jira versions but I could add the example... should I add a new example specifying "> v8.x " or do you prefer me to implement it in the same example but branching depending of a constant value for example

(EDIT) You can have a look to this example as "draft" https://github.com/andygrunwald/go-jira/pull/351
Here I have created a new folder for examples related with custom-fields, but I don't know if that is the structure we want for that.

manuelbcd avatar Feb 12 '21 10:02 manuelbcd

Hey @manuelbcd, thanks for your effort you put in already. I am very limited in time right now to have a deeper look at it. I will need some time to look at it in detail. Please excuse me when it comes to delays here.

andygrunwald avatar Feb 14 '21 12:02 andygrunwald

Sure @andygrunwald. Meanwhile I can investigate in which particular Jira versions the response was changed (I guess 8.0 but it could be earlier).

manuelbcd avatar Feb 15 '21 08:02 manuelbcd

Hello @andygrunwald , I have been navigating through Jira API documentation (from v1 to v8) and it is strange because I can't see a POST Issue (creation) response with field values within it, please have a look:

  • (Jira v1) https://docs.atlassian.com/software/jira/docs/api/REST/1000.1300.0/#api/2/issue-createIssue
  • (Jira v5) https://docs.atlassian.com/software/jira/docs/api/REST/5.2/#id250990
  • (Jira v6) https://docs.atlassian.com/software/jira/docs/api/REST/6.3.8/#d2e246 etc...

So in short, I can't check why the example https://github.com/andygrunwald/go-jira/blob/master/examples/create/main.go tries to print issue.Fields.Summary from response since it never has been part of the response. My theory is... could it be possible htat Go-Jira in the past had a feature in which Create-Issue was requesting a GET issue implicitly?

manuelbcd avatar Feb 20 '21 10:02 manuelbcd

Sadly, I don't have the time right now to look into this. @ghostsquad @rbriski @fffinkel @benjivesterby Do you have time to provide some help?

andygrunwald avatar Mar 01 '21 10:03 andygrunwald

@andygrunwald I forgot to request you to close this isse. I think it is resolved in #358 and #357

manuelbcd avatar Mar 19 '21 08:03 manuelbcd

Thanks a lot @manuelbcd!

andygrunwald avatar Mar 19 '21 09:03 andygrunwald

Hello,

I'm trying to produce a report and I'm having some issues accessing custom fields. By going through the errors I managed to get it to work, but I'm having some trouble understanding what I did and why it works, and if there is a better way to do it:

customfield_13705 is a text multiselect field. I want to access all existing teams names, and assign it to auditIssue.Teams which is of type string.

	val, _ := jiraIssue.Fields.Unknowns.Value("customfield_13705")
	var sliceOfTeams []string
	for _, team := range val.([]interface{}) {
		sliceOfTeams = append(sliceOfTeams, team.(map[string]interface{})["value"].(string))
	}
	auditIssue.Teams = strings.Join(sliceOfTeams, ", ")

jfgsilva avatar Feb 15 '23 12:02 jfgsilva