0

I need to set a value in service now user story type for epic or parent (any reference) field using create or update request of REST API in c#. I have tried setting the link and the value to the epic field to JSON object using c# class.

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

The user story is getting created with blank epic or parent field. The epic is declared like this in my class-

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

but when i am setting the value its coming like this-

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

reach2saurabh
  • 153
  • 1
  • 11

1 Answers1

1

I changed the c# object format (for json coversion) to all string properties.

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; } 
...............

and then for post or put request to servicenow I am passing additional parameter to return json response in all string.

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;

so now while updating the sys_id i can directly assign the sys_id from service now to any reference field, like epic = sys_id;

reach2saurabh
  • 153
  • 1
  • 11