0

通过 C# 我正在尝试创建具有自定义字段“销售详细信息”的 Jira 问题Atlassian SDk。下面是代码:

  string username = "XXX";
        string password = "XXX";
        string url = "https://rajasekharjira.atlassian.net";


        var settings = new JiraRestClientSettings()
        {
            EnableRequestTrace = true
        }; 
        settings.CustomFieldSerializers.Add("https://rajasekharjira.atlassian.net", new SingleObjectCustomFieldValueSerializer("Selling Details"));



        var jira = Jira.CreateRestClient(url, username, password,settings);
        var issue = jira.CreateIssue("GUID");
        issue.Type = "Bug";
        issue.Priority = "High";
        issue.Summary = "Issue Summary";
        issue.CustomFields["Selling Details"].Values[0] = "abc";

        issue.SaveChanges();

 public class SingleObjectCustomFieldValueSerializer : ICustomFieldValueSerializer
{
    //public string[] FromJson(JToken json)
    //{
    //    throw new NotImplementedException();
    //}

    //public JToken ToJson(string[] values)
    //{
    //    throw new NotImplementedException();
    //}
    private readonly string _propertyName;

    public SingleObjectCustomFieldValueSerializer(string propertyName)
    {
        this._propertyName = propertyName;
    }

    public string[] FromJson(JToken json)
    {
        return new string[1] { json[this._propertyName].ToString() };
    }

    public JToken ToJson(string[] values)
    {
        return new JObject(new JProperty(this._propertyName, values[0]));
    }
}

我在以下位置出现错误:issue.CustomFields["Selling Details"].Values[0] = "abc";

所以请让我知道如何使用自定义字段名称创建问题

我已经用 Serializer 更新了代码,但我没有得到有问题的自定义字段。CustomFields["Selling Details"].Values[0] = "abc";

4

1 回答 1

1

尝试访问自定义字段的方式是错误的,它只需要使用方括号和自定义字段的名称即可进入。

代替:

issue.CustomFields["Selling Details"].Values[0] = "abc";

利用:

issue["Selling Details"] = "abc";
于 2018-08-07T18:34:53.107 回答