Programmatically WorkItems related to Affected User - IDataItem
-
Sunday, May 20, 2012 8:39 AMModerator
Hello,
I'm busy with a custom form for the intake of an Incident.
There is a need to have a button on the form to display all related Incident work items of the selected affected user. There is information available to do this via SDK objects (EnterpriseManagementObject), but this is not what I need. The goal is to have these list of work items listed in a listView and therefore I need to use the scsm console approach and use DataAccessQuery with the IDataItem interface.
The DataAccessQuery and IDataItem interface is the not documented approach, but is used in the console. (customer idea of having this is also coming from the default console). I need to bind this to the ListView on the form so that they have a list of related work items visible, double click on the work item should open the default Incident form.
The binding and opening the default form is not a problem. The question is if there is somebody who has this already done and can put me on the right track to do this?
Reply if you need more information.
Thanks for the help!
Kurt
All Replies
-
Monday, June 11, 2012 7:37 AM
Get All Open Incident using c#
int counter =Convert.ToInt32( numericUpDown1.Value);
int ctr = 1;
String tDate = DateTime.UtcNow.ToShortDateString();
string strCriteria = @"<Criteria xmlns='http://Microsoft.EnterpriseManagement.Core.Criteria/'>
<Reference Id='System.WorkItem.Library' PublicKeyToken='{0}' Version='{1}' Alias='WorkItem' />
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='WorkItem!System.WorkItem']/CreatedDate$</Property>
</ValueExpressionLeft>
<Operator>Less</Operator>
<ValueExpressionRight>
<Value>" + tDate+@"</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
</Criteria>";
ManagementPackCriteria mpCr = new ManagementPackCriteria("Name = 'System.WorkItem.Incident.Library'");
IList<ManagementPack> mps = emGroup.ManagementPacks.GetManagementPacks(mpCr);
ManagementPackClassCriteria classCr = new ManagementPackClassCriteria("Name = 'System.WorkItem.Incident'");
IList<ManagementPackClass> classes = emGroup.EntityTypes.GetClasses(classCr);
if (mps != null && mps.Count > 0 && classes != null && classes.Count > 0)
{
ManagementPack mp = mps[0];
ManagementPackClass cl = classes[0];
// For all system management packs version and KeyToken are same.
EnterpriseManagementObjectCriteria cr = new EnterpriseManagementObjectCriteria(string.Format(strCriteria, mp.KeyToken, mp.Version), cl, mp, emGroup);
IObjectReader<EnterpriseManagementObject> reader = emGroup.EntityObjects.GetObjectReader<EnterpriseManagementObject>(cr, ObjectQueryOptions.Default);
string _status;
if (reader != null && reader.Count > 0)
{
dtIncident = new DataTable();
dtIncident.Columns.Add("Id",typeof(string));
dtIncident.Columns.Add("Name",typeof(string));
dtIncident.Columns.Add("CreateDate",typeof(string));
dtIncident.Columns.Add("Age",typeof(int));
DataRow dr = dtIncident.NewRow();
foreach (EnterpriseManagementObject obj in reader)
{
if (ctr <= counter)
{
_status = obj[null, "Status"].Value.ToString();
if (_status == "IncidentStatusEnum.Active")
{
dr[0] = obj[null, "Id"].Value.ToString();
dr[1] = obj[null, "Title"].Value.ToString();
dr[2] = Convert.ToDateTime(obj[null, "CreatedDate"].Value.ToString()).ToShortDateString();
nowDate = DateTime.Now;
span = nowDate.Subtract(Convert.ToDateTime(obj[null, "CreatedDate"].Value.ToString()));
dr[3] = Convert.ToInt32(span.Days.ToString());
dtIncident.Rows.Add(dr);
dr = dtIncident.NewRow();
ctr++;
}
}
else
{
break;
}
}
dtIncident.DefaultView.Sort = "Age Asc";
grdIncident.DataSource = dtIncident;
column = grdIncident.Columns[0];
column.MinimumWidth = 50;
column = grdIncident.Columns[1];
column.MinimumWidth = 300;
column = grdIncident.Columns[2];
column.MinimumWidth = 10;
column = grdIncident.Columns[3];
column.MinimumWidth = 10;
label2.Text = (reader.Count).ToString();
_doc = new XmlDocument();
_doc.Load("Dashboard.xml");
_node = _doc.SelectSingleNode("Dashboard/Incident/IWarningValue");
_wValue = Convert.ToBoolean(_node.InnerText);
_node = _doc.SelectSingleNode("Dashboard/Incident/IWarningRow");
_wRow = Convert.ToInt32(_node.InnerText);
_node = _node = _doc.SelectSingleNode("Dashboard/Incident/ICriticalValue");
_cValue = Convert.ToBoolean(_node.InnerText);
_node = _doc.SelectSingleNode("Dashboard/Incident/ICriticalRow");
_cRow = Convert.ToInt32(_node.InnerText);
if (_wValue && _wRow <= reader.Count)
label21.BackColor = Color.Red;
else if (!_wValue)
label21.BackColor = Color.Yellow;
else if (_wValue && _wRow > reader.Count)
label21.BackColor = Color.Yellow;
if (_cValue && _cRow <= reader.Count)
label20.BackColor = Color.Red;
if (!_cValue)
label20.BackColor = Color.Yellow;
if (_cValue && _cRow > reader.Count)
label20.BackColor = Color.Yellow;
}
}
}scsm 2012 answer

