1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Data;
using System.Data.SqlClient;
namespace ExampleEventHandlers
{
/// <summary>
/// This event handler examines a single choice field on the RDO being saved
/// to determine if the object has been marked as "Relevant". If so the artifactID
/// of the RDO is stored in an SQL table for further, say, examination by an agent.
/// </summary>
[kCura.EventHandler.CustomAttributes.Description("Example Post Save Event Handler")]
[System.Runtime.InteropServices.Guid("E99A4D1A-5157-4481-8AF7-40E634C06F4A")]
class ExamplePostSaveEventHandler : kCura.EventHandler.PostSaveEventHandler
{
private readonly Guid RELEVANT_FIELD_GUID = new Guid("5702F31B-48AC-4E2A-9000-A48B3E3ABDBF");
public override kCura.EventHandler.Response Execute()
{
//Construct a default response object.
kCura.EventHandler.Response retVal = new kCura.EventHandler.Response
{
Success = true,
Message = String.Empty
};
try
{
// Get field by GUID
kCura.EventHandler.Field relevantField = this.ActiveArtifact.Fields[RELEVANT_FIELD_GUID.ToString()];
kCura.EventHandler.ChoiceCollection fieldValue = (kCura.EventHandler.ChoiceCollection)relevantField.Value?.Value;
if (fieldValue != null)
{
// Get field value using choice name
const string choiceName = "Relevant";
kCura.EventHandler.Choice choice = fieldValue[choiceName];
// If the field value is set to the "Relevant" choice
if (choice != null)
{
// Insert artifactID of "relevant" RDO into the table in the EDDS database
Relativity.API.IDBContext eddsDbContext = Helper.GetDBContext(-1);
int workspaceArtifactID = Helper.GetActiveCaseID();
int artifactID = ActiveArtifact.ArtifactID;
AddToSqlTable(eddsDbContext, workspaceArtifactID, artifactID);
}
}
}
catch (System.Exception ex)
{
retVal.Success = false;
retVal.Message = ex.ToString();
}
return retVal;
}
/// <summary>
/// Ensure that you always have access to the fields in the ActiveArtifact.Fields collection even if they aren't on the current layout.
/// </summary>
public override kCura.EventHandler.FieldCollection RequiredFields
{
get
{
kCura.EventHandler.FieldCollection retVal = new kCura.EventHandler.FieldCollection();
retVal.Add(new kCura.EventHandler.Field(RELEVANT_FIELD_GUID));
return retVal;
}
}
/// <summary>
/// Inserts the RDO identifier into a table in the EDDS database if it doesn't already exist.
/// </summary>
/// <param name="dbContext">A database context for the EDDS database</param>
/// <param name="workspaceArtifactID">The workspace ArtifactID to insert</param>
/// <param name="artifactID">The workspace ArtifactID of the RDO in question marked "relevant".</param>
private void AddToSqlTable(Relativity.API.IDBContext dbContext, int workspaceArtifactID, int artifactID)
{
String sql = "IF NOT EXISTS(SELECT TOP 1 * FROM [MySQLTable] WHERE [WorkspaceArtifactID] = @workspaceArtifactID AND [ArtifactID] = @artifactID)"
+ " BEGIN"
+ " INSERT INTO [MySQLTable] (WorkspaceArtifactID, ArtifactID)"
+ " Values (@WorkspaceArtifactID, @artifactID)"
+ " END";
SqlParameter workspaceArtifactIDParam = new SqlParameter("@WorkspaceArtifactID", SqlDbType.Int);
workspaceArtifactIDParam.Value = workspaceArtifactID;
SqlParameter artifactIDParam = new SqlParameter("@artifactID", SqlDbType.Int);
artifactIDParam.Value = artifactID;
dbContext.ExecuteNonQuerySQLStatement(sql, new SqlParameter[] { workspaceArtifactIDParam, artifactIDParam });
}
}
}