public static ContentResult get(string numberOfRecords) { // Get credentials to use for this request. string username = ConfigurationManager.AppSettings["snUsername"]; string password = ConfigurationManager.AppSettings["snPassword"]; //initialize the client ServiceNowSoapClient client = new ServiceNowSoapClient(); //pass the credentials using basic auth client.ClientCredentials.UserName.UserName = username; client.ClientCredentials.UserName.Password = password; //set the query parameters getRecords getReq = new getRecords(); getReq.__limit = numberOfRecords; getReq.__exclude_columns = ConfigurationManager.AppSettings["cmdb_ci_ExcludedColumns"]; getReq.sys_created_on = " >= 2015-10-01"; getReq.__order_by_desc = "sys_created_on"; //get the response getRecordsResponseGetRecordsResult[] result = client.getRecords(getReq); //return the result return new ContentResult { Content = JsonConvert.SerializeObject(result), ContentType = "application/json" }; }
/// <summary> /// A private function used by NewServer for validation purposes. /// </summary> /// <param name="client">A ServiceNOW soapclient</param> /// <param name="Name">The name property of the item</param> /// <returns>true if the item exists, false if it doesn't</returns> private static bool itemExist(ServiceNowSoapClient client, string Name) { try { getRecords gRecords = new getRecords(); gRecords.name = Name; getRecordsResponseGetRecordsResult[] gResults = client.getRecords(gRecords); foreach (getRecordsResponseGetRecordsResult gResult in gResults) { if (gResult.name == Name) { // // this item already exists // return true; } } // // No match found // return false; } catch (Exception ex) { Console.WriteLine(ex.Message); return true; } }
private void cmdGetServer_Click(object sender, EventArgs e) { try { NetworkCredential Credential = new NetworkCredential(txtUsername.Text, txtPassword.Text); server.ciServer.getRecords Server = new getRecords(); //Server.sys_id = txtServer.Text; Server.name = txtServer.Text; getRecordsResponseGetRecordsResult[] Result = server.Configuration.GetServer(Credential, Server, txtUrl.Text); foreach (getRecordsResponseGetRecordsResult item in Result) { txtResult.Text += item.sys_id + "\r\n"; txtResult.Text += item.name + "\r\n"; txtResult.Text += item.asset + "\r\n"; txtResult.Text += item.comments + "\r\n"; txtResult.Text += item.department + "\r\n"; txtResult.Text += item.managed_by + "\r\n"; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// A private function used by NewServer for validation purposes. /// </summary> /// <param name="client">A ServiceNOW soapclient</param> /// <param name="Name">The name property of the item</param> /// <returns>true if the item exists, false if it doesn't</returns> private static bool itemExist(ServiceNowSoapClient client, string Name) { try { getRecords gRecords = new getRecords(); gRecords.name = Name; getRecordsResponseGetRecordsResult[] gResults = client.getRecords(gRecords); foreach (getRecordsResponseGetRecordsResult gResult in gResults) { if (gResult.name == Name) { // // this item already exists // return(true); } } // // No match found // return(false); } catch (Exception ex) { Console.WriteLine(ex.Message); return(true); } }
/// <summary> /// Get one or more servers from ServiceNOW /// </summary> /// <param name="Credential">A NetworkCredential object that gets passed to the soap client for authentication</param> /// <param name="Server">A getRecrods object that contains the data to be retreived from ServiceNOW</param> /// <returns>A getRecordsResponseGetRecordsResult array of server(s)</returns> public static getRecordsResponseGetRecordsResult[] GetServer(NetworkCredential Credential, getRecords Server, string ServiceNowUrl) { try { string userName = Credential.UserName; string userPass = Credential.Password; ServiceNowSoapClient client = soapClient(userName, userPass, ServiceNowUrl); getRecordsResponseGetRecordsResult[] result = client.getRecords(Server); return result; } catch (Exception ex) { throw ex; } }
private void cmdGetIncident_Click(object sender, EventArgs e) { try { NetworkCredential Credential = new NetworkCredential(txtUsername.Text, txtPassword.Text); getRecords myIncident = new getRecords(); myIncident.number = txtIncident.Text; getRecordsResponseGetRecordsResult[] myIncidents = incident.Incident.GetIncident(Credential, myIncident, txtUrl.Text); foreach (getRecordsResponseGetRecordsResult result in myIncidents) { txtResult.Text += result.number + "\r\n"; txtResult.Text += result.opened_by + "\r\n"; txtResult.Text += result.short_description + "\r\n"; txtResult.Text += result.u_comments_and_work_notes + "\r\n"; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void cmdGetGroup_Click(object sender, EventArgs e) { try { NetworkCredential Credential = new NetworkCredential(txtUsername.Text, txtPassword.Text); getRecords myGroup = new getRecords(); myGroup.name = txtGroup.Text; getRecordsResponseGetRecordsResult[] myIncidents = group.Group.GetGroup(Credential, myGroup, txtUrl.Text); foreach (getRecordsResponseGetRecordsResult result in myIncidents) { txtResult.Text += result.name + "\r\n"; txtResult.Text += result.description + "\r\n"; txtResult.Text += result.active + "\r\n"; txtResult.Text += result.sys_id + "\r\n"; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Get one or more incidents from ServiceNOW /// </summary> /// <param name="Credential">A NetworkCredential object that gets passed to the soap client for authentication</param> /// <param name="Incident">A getRecrods object that contains the data to be retreived from ServiceNOW</param> /// <returns>A getRecordsResponseGetRecordsResult array of incidents</returns> public static getRecordsResponseGetRecordsResult[] GetIncident(NetworkCredential Credential, getRecords Incident, string ServiceNowUrl) { try { string userName = Credential.UserName; string userPass = Credential.Password; ServiceNowSoapClient client = soapClient(userName, userPass, ServiceNowUrl); getRecordsResponseGetRecordsResult[] result = client.getRecords(Incident); return(result); } catch (Exception ex) { throw ex; } }