DIY Service Manager Analyst Portal – Part 4 – Resolving an Incident

The edit.aspx and edit.aspx.cs file is where we can go in and resolve an incident through this basic analyst portal.  Again, the HTML is fairly basic and is driven by the C# code in the background.

HTML:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="edit.aspx.cs" Inherits="edit" %>

<html>
<body>
<form id="form1" runat="server">
<div id="editInc" runat="server">
<p>
Incident Resolution Details: <asp:TextBox ID="txtIncResDetails" runat="server" Width="100%" Height="100px" TextMode="MultiLine" ></asp:TextBox>
</p>
<p>
<asp:Button id="btnUpload" Text="Resolve!" OnClick="btnUpload_Click" runat="server" Width="105px" />
</p>
<p>
<asp:Button id="btnCancel" Text="Cancel!" OnClick="btnCancel_Click" runat="server" Width="105px" />
</p>
</div>
</form>
</body>
</html>

C#:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Configuration;

public partial class edit : System.Web.UI.Page
{
String sID;
string Name;
EnterpriseManagementGroup emg;
ManagementPackClass wim;
ManagementPackRelationship wiToWi;
ManagementPackClass incidentClass;

protected void Page_Load(object sender, EventArgs e)
{
System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();
string[] a = Context.User.Identity.Name.Split('\\');

System.DirectoryServices.DirectoryEntry ADEntry;

ADEntry = new System.DirectoryServices.DirectoryEntry("WinNT://" + a[0] + "/" + a[1]);
Name = ADEntry.Properties["FullName"].Value.ToString();

Session["ID"] = Request.QueryString["ID"];

sID = Convert.ToString(Request.QueryString["ID"]);

EnterpriseManagementConnectionSettings settings = new EnterpriseManagementConnectionSettings("SCSM SERVER");
settings.UserName = "USER NAME";
char[] pass = { 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' };
settings.Password = new System.Security.SecureString();
foreach (char c in pass)
settings.Password.AppendChar(c);
settings.Domain = "DOMAIN NAME";

emg = new EnterpriseManagementGroup(settings);

ManagementPack mpSystem = emg.ManagementPacks.GetManagementPack(SystemManagementPack.System);

Version version = mpSystem.Version;
string keytoken = mpSystem.KeyToken;

ManagementPack incidentManagementMP = emg.ManagementPacks.GetManagementPack("System.WorkItem.Incident.Library", "31bf3856ad364e35", null);
incidentClass = emg.EntityTypes.GetClass("System.WorkItem.Incident", incidentManagementMP);
ManagementPack workItemManagementMP = emg.ManagementPacks.GetManagementPack("System.WorkItem.Library", "31bf3856ad364e35", null);
wim = emg.EntityTypes.GetClass("System.WorkItem.TroubleTicket.AnalystCommentLog", workItemManagementMP);
wiToWi = workItemManagementMP.GetRelationship("System.WorkItem.TroubleTicketHasAnalystComment");
}

protected void btnUpload_Click(object sender, EventArgs e)
{
foreach (EnterpriseManagementObject incident in emg.EntityObjects.GetObjectReader<EnterpriseManagementObject>(new EnterpriseManagementObjectGenericCriteria("Name='" + sID + "'"), ObjectQueryOptions.Default))
{
EnterpriseManagementObjectProjection emoAnalyst = new EnterpriseManagementObjectProjection(emg, wim);
emoAnalyst.Object[wim, "Id"].Value = Guid.NewGuid().ToString();
emoAnalyst.Object[wim, "Comment"].Value = txtIncResDetails.Text + "\n";
emoAnalyst.Object[wim, "EnteredBy"].Value = Name;
emoAnalyst.Object[wim, "EnteredDate"].Value = DateTime.Now.ToUniversalTime();
emoAnalyst.Object[wim, "DisplayName"].Value = "Record Resolved";
emoAnalyst.Object[wim, "IsPrivate"].Value = "False";
EnterpriseManagementObjectProjection emoIncident = new EnterpriseManagementObjectProjection(incident);
emoIncident.Add(emoAnalyst, wiToWi.Target);

//Set incident to resolved
string sResolvedStatusGuid = "2B8830B6-59F0-F574-9C2A-F4B4682F1681";
incident[incidentClass, "Status"].Value = new Guid(sResolvedStatusGuid);
//Set resolved classification to "Fixed my technician"
string sResolvedCategory = "C5F6ADA9-A0DF-01D6-7087-6B8500CA6C2B";
incident[incidentClass, "ResolutionCategory"].Value = new Guid(sResolvedCategory);
incident[incidentClass, "ResolvedDate"].Value = DateTime.UtcNow;
incident[incidentClass, "ResolutionDescription"].Value = txtIncResDetails.Text + "\n";

emoIncident.Commit();
emoIncident.Overwrite();
}

emg.Dispose();
Response.Redirect("default.aspx");
}

protected void btnCancel_Click(object sender, EventArgs e)
{
emg.Dispose();
Response.Redirect("default.aspx");
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s