ReportingEventReceiver.OnCustomFieldCreated Method
A post-event handler in the Report Data Service for creating a custom field.
Namespace: Microsoft.Office.Project.Server.Events
Assembly: Microsoft.Office.Project.Server.Events.Receivers (in Microsoft.Office.Project.Server.Events.Receivers.dll)
Syntax
'Declaration
Public Overridable Sub OnCustomFieldCreated ( _
contextInfo As PSContextInfo, _
e As ReportingPostCustomFieldCreatedEventArgs _
)
'Usage
Dim instance As ReportingEventReceiver
Dim contextInfo As PSContextInfo
Dim e As ReportingPostCustomFieldCreatedEventArgs
instance.OnCustomFieldCreated(contextInfo, _
e)
public virtual void OnCustomFieldCreated(
PSContextInfo contextInfo,
ReportingPostCustomFieldCreatedEventArgs e
)
Parameters
- contextInfo
Type: Microsoft.Office.Project.Server.Library.PSContextInfo
Contains the Project Server context information.
- e
Type: Microsoft.Office.Project.Server.Events.ReportingPostCustomFieldCreatedEventArgs
The data for the event.
Remarks
The Report Data Service raises the Reporting custom field created event when the Reporting database is updated with the custom field information. The PSI methods CreateCustomFields and CreateCustomFields2 raise a custom field created event before the Reporting event. These events can be very close in time.
ReportingCustomFieldMetadataDataSet provides metadata needed by the reporting system when transferring custom field information to the RDS. The value of the CustomFieldTypeUID dataset member can also be found in the event argument property e.CustomFieldTypeGUID.
The names of these two entities include the word “Type” however these values are not associated with the type of the custom field (Cost, Date, Duration, Flag, Number, or Text), rather to the type of the GUID (custom field).
For more information about RDS events for the Reporting database, see Events for the RDB.
Examples
The following is an example of a custom field created post-event handler. The example OnCustomFieldCreated method retrieves information from the event parameters and writes it to an XML file.
using System;
using System.Data;
using System.IO;
using System.Text;
using Microsoft.Office.Project.Server.Events;
using PSLib = Microsoft.Office.Project.Server.Library;
using PSSchema = Microsoft.Office.Project.Server.Schema;
namespace Microsoft.SDK.Project.Samples.ReportingEvents
{
public class TestCustomFieldCreated : ReportingEventReceiver
{
// Change the output directory for your computer.
private const string OUTPUT_FILES = @"C:\Project\Samples\Output\";
private static string outFilePath;
public override void OnCustomFieldCreated(PSLib.PSContextInfo
contextInfo, ReportingPostCustomFieldCreatedEventArgs e)
{
// Record the time of the event.
DateTime eventRaised = DateTime.Now;
// Create the location for the output file.
outFilePath = OUTPUT_FILES + "ReportingCustomFieldCreatedTestOutput.txt";
// Write event argument information to the output file.
string eventData = "\r\n\r\nCustom Field Created post-event handler: " + eventRaised.ToString();
eventData += "\r\nPWA site Guid: " + contextInfo.SiteGuid.ToString();
eventData += "\r\nUser name: " + contextInfo.UserName;
eventData += "\r\nUser Guid: " + contextInfo.UserGuid;
eventData += "\r\nCustom field type GUID: " + e.CustomFieldTypeGuid.ToString();
// Include the reporting metadata for the custom field.
PSSchema.ReportingCustomFieldMetadataDataSet projectDs = e.CustomFieldMetadataDataSet;
projectDs.WriteXml(outFilePath);
using (StreamWriter outputData = new StreamWriter(outFilePath, true))
{
outputData.WriteLine();
outputData.WriteLine(eventData);
outputData.Close();
}
}
}
}
The following example lists the contents of the ReportingCustomFieldCreatedTestOutput.txt file that is written by the application.
Note
The custom field information in the example is specific to the custom field that is defined in a Project Web App instance.
<?xml version="1.0" standalone="yes"?>
<ReportingCustomFieldMetadataDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/ReportingCustomFieldMetadataDataSet/">
<CustomFieldMetadata>
<CustomFieldTypeUID>1e1dfb97-b4fc-4d8a-aaa8-b1ad079a2013</CustomFieldTypeUID>
<ParentEntityTypeGuid>cecfe271-6660-4abe-97ed-208d3c71fc18</ParentEntityTypeGuid>
<CustomFieldName>Test Project Text CF - has LUT</CustomFieldName>
<CustomFieldType>21</CustomFieldType>
<LookupTableUID>cdff825e-8951-4ac7-ad0e-ba28a009dd1d</LookupTableUID>
<IsMultiValueEnabled>false</IsMultiValueEnabled>
<HasWeights>false</HasWeights>
<AssignmentRollDown>false</AssignmentRollDown>
<CreatedDate>2011-03-28T18:45:31.827-07:00</CreatedDate>
<ModificationDate>2011-03-28T18:45:31.827-07:00</ModificationDate>
</CustomFieldMetadata>
</ReportingCustomFieldMetadataDataSet>
Custom Field Created post-event handler: 3/28/2011 6:45:40 PM
PWA site GUID: 9f110f4a-3632-42d3-a1e5-21f9c43360c3
User name: DOMAIN\UserName
User GUID: 2e0fdcc1-85fc-4bde-9593-78a2789c66af
Custom field type GUID: 1e1dfb97-b4fc-4d8a-aaa8-b1ad079a2013