如何使用Rest API为服务中的史诗级或用户故事中的引用字段设置值

时间:2019-06-03 12:29:08

标签: c# servicenow servicenow-rest-api

我需要使用c#中REST API的创建或更新请求,为史诗或父级(任何引用)字段中的now now用户故事类型设置一个值。我已经尝试使用c#类将链接和值的史诗字段设置为JSON对象。

storyObj.epic.link="https://<companyname>.service-now.com/api/now/table/rm_epic/{sys_id}";    storyObj.epic.value= "{sys_id}";

正在使用空白的史诗或父字段创建用户故事。 史诗在我的课堂上是这样宣告的

 public Epic epic { get; set; } public class Epic
{
    public string link { get; set; }
    public string value { get; set; }
 }

但是当我设置值时,它会像这样-

"epic": { "link": "https://company.service-now.com/api/now/table/rm_epic/{value=d385c54adbb5bb00f493894d0", "value": "{value=d385c54adbb5bb00f493894d0" },

1 个答案:

答案 0 :(得分:1)

我将c#对象格式(用于json覆盖)更改为所有字符串属性。

public string epic { get; set; }  
public string parent { get; set; }
public string shadow { get; set; }
public string watch_list { get; set; }
public string phase_type { get; set; } 
...............

,然后向服务发布或放置请求,现在我传递附加参数以在所有字符串中返回json响应。

HttpClient httpClient = ContectToServiceNow();
var content = new StringContent(json.ToString(), UnicodeEncoding.UTF8, 
"application/json");
response = httpClient.PostAsync("api/now/table/" + tableName + "? 
sysparm_exclude_reference_link=true", content).Result;

现在在更新sys_id时,我可以直接将服务中的sys_id分配给任何参考字段,例如     epic = sys_id;