The Jira Field Context Configurations define the scope of custom fields within Jira. They determine where and how a custom field can be used within Jira, such as in which projects, issue types, and screens the field should be available. Field Context Configurations are used to ensure that the right data is captured and displayed in Jira, and that users are not presented with irrelevant fields.
for a custom field. Contexts can be returned as follows:
With no other parameters set, all contexts.
By defining id only, all contexts from the list of IDs.
By defining isAnyIssueType, limit the list of contexts returned to either those that apply to all issue types (true) or those that apply to only a subset of issue types (false)
By defining isGlobalContext, limit the list of contexts return to either those that apply to all projects (global contexts) (true) or those that apply to only a subset of projects (false)
Creates a custom field context. If projectIds is empty, a global context is created. A global context is one that applies to all project. If issueTypeIds is empty, the context applies to all issue types, the method returns the following information:
packagemainimport ("context""github.com/ctreminiom/go-atlassian/jira/v2""github.com/ctreminiom/go-atlassian/pkg/infra/models""log""os")funcmain() {var ( host = os.Getenv("HOST") mail = os.Getenv("MAIL") token = os.Getenv("TOKEN") ) atlassian, err := v2.New(nil, host)if err !=nil {return } atlassian.Auth.SetBasicAuth(mail, token)var fieldID ="customfield_10038" payload :=models.FieldContextPayloadScheme{ IssueTypeIDs: []int{10004}, ProjectIDs: []int{10002}, Name: "Bug fields context $3 aaw", Description: "A context used to define the custom field options for bugs.", } contextCreated, response, err := atlassian.Issue.Field.Context.Create(context.Background(), fieldID, &payload)if err !=nil { log.Fatal(err)return } log.Println("HTTP Endpoint Used", response.Endpoint) log.Println(contextCreated)}
Get custom field contexts default values
GET /rest/api/{2-3}/field/{fieldId}/context/defaultValue
Returns a paginated list of defaults for a custom field. The results can be filtered by contextId, otherwise all values are returned. If no defaults are set for a context, nothing is returned.
packagemainimport ("context""github.com/ctreminiom/go-atlassian/jira/v2""log""os")funcmain() {var ( host = os.Getenv("HOST") mail = os.Getenv("MAIL") token = os.Getenv("TOKEN") ) atlassian, err := v2.New(nil, host)if err !=nil {return } atlassian.Auth.SetBasicAuth(mail, token)var fieldID ="customfield_10038" defaultValues, response, err := atlassian.Issue.Field.Context.GetDefaultValues(context.Background(), fieldID, nil, 0, 50)
if err !=nil {return } log.Println("HTTP Endpoint Used", response.Endpoint)for _, value :=range defaultValues.Values {/* For singleOption customField type, use value.OptionID For multipleOption customField type, use value.OptionIDs For cascadingOption customField type, use value.OptionID and value.CascadingOptionID */ log.Println(value) }}
Set custom field contexts default values
PUT /rest/api/{2-3}/field/{fieldId}/context/defaultValue
Sets default for contexts of a custom field. Default is defined using these objects:
Only one type of default object can be included in a request. To remove a default for a context, set the default parameter to null.
GET /rest/api/{2-3}/field/{fieldId}/context/projectmapping
Returns a paginated list of context to project mappings for a custom field. The result can be filtered by contextId. Otherwise, all mappings are returned. Invalid IDs are ignored.