Get a list of incidents

jspatton1971
Kilo Explorer

I'm just getting started with servicenow integrations and c-sharp. I've been working in c-sharp for a while, but don't think i'd call myself an expert. I tend to start small and work up so for my first task, I wanted to create an app that would return a list of active incidents. Early on I was getting access errors but have updated my app.config with the appropriate transport information, I also had to add a maxRecevievedMessageSize as I was getting an error that I was exceeding that.

My code is fairly straightforward and I *think* it should work. Please let me know what I'm doing wrong here? I have one incident that is active in my test instance, and i'm logged in as admin, and that is the user who created and is assigned to the one active incident.

ServiceNOW.ServiceNowSoapClient soapClient = new ServiceNOW.ServiceNowSoapClient();
soapClient.ClientCredentials.UserName.UserName = "blah";
soapClient.ClientCredentials.UserName.Password = "blah";

ServiceNOW.getRecords Records = new ServiceNOW.getRecords();
Records.state = "Active";
ServiceNOW.getRecordsResponseGetRecordsResult[] Results = soapClient.getRecords(Records);
foreach (ServiceNOW.getRecordsResponseGetRecordsResult Result in Results)
{
string consoleReturn = Result.sys_id + " " + Result.opened_by + " " + Result.short_description;
Console.WriteLine(consoleReturn);
}

10 REPLIES 10

john_andersen
Tera Guru

I am not a c# guru, but will give you a few resources that hopefully might help when creating a C# integration with servicenow. (you may have already seen these):

End to End example:
http://wiki.servicenow.com/index.php?title=Web_Services_C_Sharp_.NET_End_to_End_Tutorial

Demo video I created a while back:
http://www.john-james-andersen.com/blog/service-now/set-up-c-client-to-submit-soap-calls-to-servicenow.html

Persisting SOAP connections with C#:
http://www.john-james-andersen.com/blog/service-now/persisting-soap-connections-csharp.html

Also, do forget to set your ElementFormDefault property correctly on your instance:
http://wiki.servicenow.com/?title=Direct_Web_Services#Compatibility_for_Clients_Generated_from_WSDL


John,

Ok, for starters I've changed my sample app, and I am able to create an incident just fine. The weird thing is, I'm not getting an incident number back in my response. I more or less lifted the code from your example so it looks the same. In fact, after stepping through the code it appears that my insert response is null for all properties, yet I'm getting the incidents showing up.

ServiceNOW.ServiceNowSoapClient soapClient = new ServiceNOW.ServiceNowSoapClient();
soapClient.ClientCredentials.UserName.UserName = "blah";
soapClient.ClientCredentials.UserName.Password = "blah";

ServiceNOW.insert newIncident = new ServiceNOW.insert();
ServiceNOW.insertResponse incidentResponse = new ServiceNOW.insertResponse();

newIncident.category = "Request";
newIncident.comments = "Please install backup software.";
newIncident.short_description = "networker client install";
newIncident.caller_id = "bud.richman";
newIncident.assigned_to = "admin";

try
{
incidentResponse = soapClient.insert(newIncident);
Console.WriteLine("Incident # Below");
Console.WriteLine(incidentResponse.number);
Console.WriteLine("Incident # Above");
}
catch (Exception error)
{
Console.WriteLine(error);
}


jason_petty
Tera Expert

I am guessing that the Records.state = "Active"; may be wrong there. You want to set that to a number instead?

There is a good video that John Andersen made about doing C# with ServiceNow that might help:
http://www.john-james-andersen.com/blog/service-now/set-up-c-client-to-submit-soap-calls-to-servicenow.html


It seems that this is stored as a number but when you search for it it's a string. I tried passing in state as an int, and was told it should be a string. so when I passed the variable as string with an integer value I got a response.

seems odd to me.