Reading Enterprise RBS values: the Easy Way and the Not-So-Easy Way

There are a couple of ways to programmatically get the Resource Breakdown Structure (RBS) value for a Project Server user. The simplest way is to query the Reporting database, for example:

 SELECT [ResourceUID] ,[ResourceName] ,[ResourceBookingType] ,[ResourceIsActive] ,[RBS] FROM [ProjectServer_Reporting].[dbo].[MSP_EpmResource_UserView] AS res WHERE res.ResourceName = N'Linda Jones'

The result on my machine is:







Linda Jones



User Assistance.DevDocs.SDK Writers

To get the RBS by using the PSI is a bit more work. Because the RBS is an enterprise resource custom field that uses the RBS lookup table, you can use the following steps:

  1. Call the ReadResources method and filter the primary Resources table for the user name and GUID. Alternately, you can use the ReadUserList method to get all of the active resource names and GUIDs, and iterate through the ResourceDataSet for the specific resource. The attached example uses the –userList command line argument to have the application use the ReadUserList method, and displays the elapsed time for the method used.
  2. Call ReadResource with the resource GUID to get the full ResourceDataSet.
  3. Iterate through the ResourceDataSet. ResourceCustomFields table to get the CODE_VALUE for the RBS custom field (if it exists).
  4. Use a filter with the ReadLookupTables method to get a LookupTableDataSet that contains only the LookupTableTrees table for the RBS lookup table.
  5. Iterate through the LookupTableTrees table to get the LT_VALUE_FULL string that corresponds to the CODE_VALUE in the RBS custom field. The LookupTableTrees row where the LT_STRUCT_UID element matches the custom field CODE_VALUE contains the correct RBS string.

The attached example also writes the various datasets to XML files, for debugging purposes. Keep in mind that the app user must have the ManageUsersAndGroups global permission, and the other permissions specified in the SDK topics for the methods used, in order to read data of other resources.

The attached file contains the complete Visual Studio solution for the example described in this post. To use the sample, change the server name and Project Server name for the endpoint addresses in the app.config file. The sample uses the WCF interface for Project Server 2010; however, it can be adapted to use the ASMX interface for Project Server 2007.

For example, the following command gets the same RBS value shown by the Reporting database query:

 C:\Test>ReadRbs -name "Linda Jones"

XML output from ReadResources:

Using ReadResources method: 412.309 milliseconds

XML output from ReadResource:

XML output from ReadLookupTables:

User name: Linda Jones
GUID: 0D455775-01CB-42E1-A481-A6F0F1F8208A
RBS value: User Assistance.DevDocs.SDK Writers

Press any key to exit...