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

Documentation for custom jira fields #350

Open
pH-T opened this issue Feb 10, 2021 · 14 comments
Open

Documentation for custom jira fields #350

pH-T opened this issue Feb 10, 2021 · 14 comments

Comments

@pH-T
Copy link

pH-T commented Feb 10, 2021

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

@github-actions
Copy link

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.

@manuelbcd
Copy link
Contributor

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.

@pH-T
Copy link
Author

pH-T commented Feb 10, 2021

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...

@manuelbcd
Copy link
Contributor

manuelbcd commented Feb 11, 2021

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

(Source #257 (comment) )

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: #117

Pls let us know if that helps

@pH-T
Copy link
Author

pH-T commented Feb 11, 2021

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

@andygrunwald
Copy link
Owner

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.

@manuelbcd
Copy link
Contributor

manuelbcd commented Feb 12, 2021

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" #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.

@andygrunwald
Copy link
Owner

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.

@manuelbcd
Copy link
Contributor

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
Copy link
Contributor

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:

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?

@andygrunwald
Copy link
Owner

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?

@manuelbcd
Copy link
Contributor

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

@andygrunwald
Copy link
Owner

Thanks a lot @manuelbcd!

@jfgsilva
Copy link

jfgsilva commented Feb 15, 2023

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, ", ")

@andygrunwald andygrunwald reopened this Feb 15, 2023
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

4 participants