使用atlassian SDK创建具有自定义字段名称的Jira问题

时间:2018-01-23 06:48:37

标签: c# jira atlassian-plugin-sdk

通过C#我正在尝试创建具有自定义字段"销售详细信息"使用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更新了代码,但我没有在 issue.CustomFields ["销售详细信息"]中获取自定义字段。值[0] =" abc"

1 个答案:

答案 0 :(得分:0)

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

代替:

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

使用:

issue["Selling Details"] = "abc";