locked
How to add Analyst Comments to Incident? RRS feed

  • Question

  • Hi everyone, i have this situation, when i try to add a new Analyst comment in C# with next code, appear this error: 

    "A discovery data item was rejected because the item has already been inserted by another user or process."

    I dont clear if projectionIncident.Object[classIncident, "Id"].Value correspond to Incident ID.

    EnterpriseManagementGroup emg = new EnterpriseManagementGroup(ManagementServer);
    ManagementPack mpSystem = emg.ManagementPacks.GetManagementPack(SystemManagementPack.System);
    Version version = mpSystem.Version;
    string keytoken = mpSystem.KeyToken;
    ManagementPack mpIncidentLibrary = emg.GetManagementPack("System.WorkItem.Library", keytoken, version);
    ManagementPackClass classIncident = emg.EntityTypes.GetClass("System.WorkItem.TroubleTicket.AnalystCommentLog", mpIncidentLibrary);
    EnterpriseManagementObjectProjection projectionIncident = new EnterpriseManagementObjectProjection(emg, classIncident);
    projectionIncident.Object[classIncident, "Id"].Value = "IR75";
    projectionIncident.Object[classIncident, "Comment"].Value = "Incident updated via SDK.\n";
    projectionIncident.Object[classIncident, "EnteredBy"].Value = "Incident updated via SDK";
    projectionIncident.Object[classIncident, "EnteredDate"].Value = DateTime.Now.ToUniversalTime();
    projectionIncident.Object[classIncident, "DisplayName"].Value = "IR75";
    projectionIncident.Object[classIncident, "IsPrivate"].Value = "True";             
    //projectionIncident.Overwrite();
    projectionIncident.Commit();

    Somebody help me, please?

    Monday, March 19, 2012 3:15 PM

Answers

  • Here is the solution:

    ManagementPack incidentManagementMP = emg.ManagementPacks.GetManagementPack("System.WorkItem.Incident.Library", keytoken, version);
    ManagementPackClass incidentClass = emg.EntityTypes.GetClass("System.WorkItem.Incident", incidentManagementMP);

    ManagementPack workItemManagementMP = emg.ManagementPacks.GetManagementPack("System.WorkItem.Library", keytoken, version);
    ManagementPackClass wi = emg.EntityTypes.GetClass("System.WorkItem.TroubleTicket.AnalystCommentLog", workItemManagementMP);
    ManagementPackRelationship wiToWi = workItemManagementMP.GetRelationship("System.WorkItem.TroubleTicketHasAnalystComment");
               
    foreach (EnterpriseManagementObject incident in emg.EntityObjects.GetObjectReader<EnterpriseManagementObject>(new EnterpriseManagementObjectGenericCriteria("Name='IR37'"), ObjectQueryOptions.Default))
    {

    EnterpriseManagementObjectProjection emoAnalyst = new EnterpriseManagementObjectProjection(emg, wi);
    emoAnalyst.Object[wi, "Id"].Value = Guid.NewGuid().ToString();
    emoAnalyst.Object[wi, "Comment"].Value = "Incident updated via SDK.\n";
    emoAnalyst.Object[wi, "EnteredBy"].Value = "Incident updated via SDK";
    emoAnalyst.Object[wi, "EnteredDate"].Value = DateTime.Now.ToUniversalTime();
    emoAnalyst.Object[wi, "DisplayName"].Value = "IR37Comentario";
    emoAnalyst.Object[wi, "IsPrivate"].Value = "True";

    EnterpriseManagementObjectProjection emoIncident = new EnterpriseManagementObjectProjection(incident);
    emoIncident.Add(emoAnalyst, wiToWi.Target);
    emoIncident.Commit();

    }


    David L.

    Monday, March 19, 2012 8:20 PM