Project Financial Server Events in CU4

Code Samples, Project Financial Server, SDK

CU4 introduces a couple of new events which have been deemed necessary to accomodate customer requests. This post will update the previous post on the subject, with additional definitions and a code sample.

First, the 2 new events are:

Event Name Event Type PFSEventID value Description
FinancialValuesRead Filter event PFSEventID.FinancialValuesRead (10) The event fires after the data has been read and before it will be displayed in the grids
ReportingCompleted Post-event PFSEventID.ReportingCompleted (11) The event fires to notify that relevant data was copied to the reporting database

The signatures for the two events are:

FinancialValuesEventsReceiver.OnFinancialValuesRead(PSContextInfo context, ReadValuesEventArgs e);
FinancialValuesEventsReceiver.OnReportingCompleted(PSContextInfo context, ReportingEventArgs e);

A sample to demonstrate the new Read event is below. In this scenario, we display the values in thousand dollars instead of dollars for the resources in the Executive group.

 class CU4EventsReceiver : FinancialValuesEventsReceiver
    {
        public override void OnFinancialValuesRead(PSContextInfo context, ReadValuesEventArgs e)
        {
            Guid projectUid = e.ProjectUid;            
            if (IsSummaryResource(context))
            {
                // if summary resource, display all the values in K$ (thousands dollars)
                foreach (ValueInfo.cmFinancialValuesRow valueRow in e.Values.cmFinancialValues)
                {
                    valueRow.Value = valueRow.Value / 1000;
                }
                e.Currency = "K$";
                e.IsGridReadOnly = true; // this view is readonly
                e.Values.AcceptChanges(); // commit changes to the dataset.
            }            
        }

        private bool IsSummaryResource(PSContextInfo context)
        {
            // call PSI to find out the security groups the current user is part of
            // the current user is in the context (UserGuid / UserName)
            PSI psi = new PSI(PSContextInfo.SerializeToString(context));
            ResourceAuthorizationDataSet rsds = psi.ResourceWebService.ReadResourceAuthorization(context.UserGuid);
            if (rsds.GroupMemberships.FindByRES_UIDWSEC_GRP_UID(context.UserGuid, PSSecurityGroup.Executives) != null)
                return true;

            return false;
        }

    }

What do you think?