OnCustomFieldCreated method
Collapse the table of content
Expand the table of content

ReportingEventReceiver.OnCustomFieldCreated method

Office 2013 and later

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)

public virtual void OnCustomFieldCreated(
	PSContextInfo contextInfo,
	ReportingPostCustomFieldCreatedEventArgs e


Type: Microsoft.Office.Project.Server.Library.PSContextInfo

Contains the Project Server context information.

Type: Microsoft.Office.Project.Server.Events.ReportingPostCustomFieldCreatedEventArgs

The data for the event.

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.

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;

            using (StreamWriter outputData = new StreamWriter(outFilePath, true))

The following example lists the contents of the ReportingCustomFieldCreatedTestOutput.txt file that is written by the application.


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="http://schemas.microsoft.com/office/project/server/webservices/ReportingCustomFieldMetadataDataSet/">
    <CustomFieldName>Test Project Text CF - has LUT</CustomFieldName>

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
© 2016 Microsoft