Problem in Event Handler 2007. RRS feed

  • Question

  • Hi all,

    Scenario:- On recource created i want enter resouce name in a look up table called "projectManager"

    incase resource belongs to projectmanager group...

    Please check code and suggest me


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using PSLibrary=Microsoft.Office.Project.Server.Library;
    using Microsoft.Office.Project.Server.Events;
    using wss=Microsoft.SharePoint;
    namespace ClassLibrary1
      public class Resource : ResourceEventReceiver
        public static Resourcewe.Resource r = new ClassLibrary1.Resourcewe.Resource();
        public static LookUpTable1.LookupTable l = new ClassLibrary1.LookUpTable1.LookupTable();
        Guid[] lookupguid;
        public override void OnCreated(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo, ResourceCreatePostEventArgs e)
          base.OnCreated(contextInfo, e);
          string resourcename = e.CreatedResources.ToString();
          string ru = e.CreatedResources.GetValue(0).ToString();
          Guid siteguid = contextInfo.SiteGuid;
          string pwaurl = new wss.SPSite(siteguid).Url;
          //int eventId = 7777;
          LookUpTable1.LookupTableMultiLangDataSet lds = new ClassLibrary1.LookUpTable1.LookupTableMultiLangDataSet();
          // LookUpTable1.LookupTableDataSet.LookupTableTreesRow lrow = lds.LookupTableTrees.NewLookupTableTreesRow();
          LookUpTable1.LookupTableMultiLangDataSet.LookupTablesRow lrow=lds.LookupTables.NewLookupTablesRow();
          PSLibrary.Filter lookupfilter = new Microsoft.Office.Project.Server.Library.Filter();
          lookupfilter.FilterTableName = lds.LookupTables.TableName;
          //lookupfilter.Fields.Add(new PSLibrary.Filter.Field(lds.LookupTables.TableName, lds.LookupTables.LT_NAMEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
          //lookupfilter.Fields.Add(new PSLibrary.Filter.Field(lds.LookupTables.TableName, lds.LookupTables.LT_UIDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
          PSLibrary.Filter.FieldOperator existinglookup = new Microsoft.Office.Project.Server.Library.Filter.FieldOperator(PSLibrary.Filter.FieldOperationType.Equal, lds.LookupTables.LT_NAMEColumn.ColumnName, "projectManager");
          lookupfilter.Criteria = existinglookup;
          string lookupxml = lookupfilter.GetXml();
          lds = l.ReadLookupTablesMultiLang(lookupxml, false);
          Resourcewe.ResourceDataSet resourceDs=new ClassLibrary1.Resourcewe.ResourceDataSet();
          PSLibrary.Filter resourceFilter = new Microsoft.Office.Project.Server.Library.Filter();
          resourceFilter.FilterTableName = resourceDs.Resources.TableName;
          //resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_UIDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
          //resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_GROUPColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
          PSLibrary.Filter.FieldOperator existingResource = new Microsoft.Office.Project.Server.Library.Filter.FieldOperator(PSLibrary.Filter.FieldOperationType.Equal, resourceDs.Resources.RES_NAMEColumn.ColumnName, resourcename);
          resourceFilter.Criteria = existingResource;
          String filterXml = resourceFilter.GetXml();
          resourceDs = r.ReadResources(filterXml, false);
          String groupname = resourceDs.Resources[0].RES_GROUP;
          lookupguid[0] = lds.LookupTables[0].LT_UID;
          if (groupname == "Project Managers")
            LookUpTable1.LookupTableMultiLangDataSet.LookupTableStructuresRow lutStructureRow =
            lutStructureRow.LT_UID = lookupguid[0];
            lutStructureRow.LT_STRUCT_UID = Guid.NewGuid();
            LookUpTable1.LookupTableMultiLangDataSet.LookupTableValuesRow lutValueRow =
            lutValueRow.LCID = 1033;
            lutValueRow.LT_VALUE_DESC = "This is root label A";
            lutValueRow.LT_VALUE_DUR = 30;
            lutValueRow.LT_VALUE_DUR_FMT = (byte)PSLibrary.Task.DurationFormat.Hour;
            lutValueRow.LT_STRUCT_UID = lutStructureRow.LT_STRUCT_UID;
            lutValueRow.LT_UID = lutStructureRow.LT_UID;
            bool validateOnly = false;
            bool autoCheckIn = true;
            l.UpdateLookupTablesMultiLang(lds, validateOnly, autoCheckIn);
            //lrow.LT_UID = new Guid();
            //lrow.LT_STRUCT_UID = new Guid();
            //lrow.LT_VALUE_TEXT = resourcename;
            //lrow.LT_VALUE_SORT_INDEX = (byte)PSLibrary.LookupTables.SortOrder.Ascending;


    Thursday, June 23, 2011 3:46 PM

All replies

  • Hey Nitin,

    What is the issue? Did you register the event & verified that code is not working ..or throwing exceptions? 


    Thanks, Amit Khare |EPM Consultant| Blog:
    Friday, June 24, 2011 5:19 AM
  • Code was not working....

    so please correct me where am i doing wrong?


    Friday, June 24, 2011 12:54 PM
  • Nitin,
    By lloking at the code, It seems that you are adding the name of the resource in Projectmanager lookup table if the resource is in project manager group? I dont see if you are calling the SecurityWebservice to find the resource security group? Also, If you make change in the code, You might need to revisit the design to handle if the existing user is grouop is updated to Project manager. (On a Resource update)

    Did you register the event handler &  try to debug the same? Try to write in Eventlog on exception & follow the article:

    Does that help?

    Thanks, Amit Khare |EPM Consultant| Blog:
    Tuesday, July 12, 2011 9:10 AM
  • I have not tried your code, but what i can observe is when you create the resourceDs = r.ReadResources(filterXml, false); the, this dataset is not updated properly so, due to that reason you are not getting the Resource dataset and you will not get the newly created resource, 

    There are 2 approach you can do:

    1 ) EventHandler on the Reporting Event

    2) you an write a console application which runs every day and syncs all the resources in the Lookup table.

    Otherwise your code looks good.

    Thanks, Parth
    • Proposed as answer by Parth Rawal Thursday, July 28, 2011 5:07 AM
    Thursday, July 28, 2011 5:07 AM