0

拜托,您能帮我从名称中有空格的自定义字段创建/更新项目吗?

我们有一个带有自定义字段的项目Contact phone。该字段可以在浏览器中正确使用。https://github.com/Workfront/workfront-api-examples-csharp没有帮助。我能够在问题的详细信息中添加数据。我想在特定的自定义字段中添加它(创建/更新)。

var client = new AtTaskRestClient(_url); // from the example
...
var description = $"Contact phone: {item.ContactPhone}";
client.Create(ObjCode.ISSUE, new { name = item.Name,
    description = description,
    projectID = _projectID });

client.Create有一个对象作为最终参数。我们使用不能包含"DE:Contact phone" = item.ContactPhone在构造函数中的匿名类型。我们如何写这个字段?

DE:Contact phone如果我们从浏览器插入值,读取工作正常:

JToken issues = client.Search(ObjCode.ISSUE, new { projectID = _projectID });
foreach (var issue in issues["data"].Children()) {
    var name = issue.Value<string>("name"); // correct
    var id = issue.Value<string>("ID"); // correct
    var fields = client.Get(ObjCode.ISSUE, id, new[] { "description", "DE:Contact phone"}); // correct
4

1 回答 1

0

https://github.com/Workfront/workfront-api-examples-csharp/blob/master/AtTaskRestExample/AtTaskRestClient.cs

public JToken Create(ObjCode objcode, object parameters) {
    VerifySignedIn();
    string[] p = parameterObjectToStringArray(parameters, "sessionID=" + SessionID);
    JToken json = client.DoPost(string.Format("/{0}", objcode), p);
    return json;
}

我写了一个新函数 CreateEx,它接收一个字符串数组

public JToken Create(ObjCode objcode, string[] parameters) {
    VerifySignedIn();
    JToken json = client.DoPost(string.Format("/{0}", objcode), parameters);
    return json;
}

访问方式如下:

var client = new AtTaskRestClient(_url); // from the example
...
string[] parameteres =
    {
        $"name={issueName}",
        $"description={description}",
        $"projectID={_projectID}",
        $"sessionID={client.SessionID}",
        $"DE:Contact phone={contactPhone}"
    };
client.CreateEx(ObjCode.ISSUE, parameteres);
于 2017-12-08T08:52:03.727 回答