Data Solutions

Get value in a MS Project lookup table

The following VSTO C# function will let you pass in the name of the Microsoft Project lookup table. It will use the PSI (Project Server web service) to get the values in the lookup table and return them as a data table.

using System;
using System.Data;
using System.Net;
using System.Net.Mail;
using MSProject = Microsoft.Office.Interop.MSProject;
using PSLibrary = Microsoft.Office.Project.Server.Library;

/// <summary>
/// Returns the values in a lookup table as a DataTable
/// </summary>
/// <param name="lookupTableName">The name of the lookup table as a string</param>
/// <returns>A DataTable with the Values of the LookupTable.
///     LT_Value_Text is the ID (or Value) column
///     LT_Value_Desc is the Description column</returns>
internal static DataTable GetLookupTable(string lookupTableName)
    LookupTableWebSvc.LookupTable LookupWebSvc;
    LookupWebSvc = new LookupTableWebSvc.LookupTable();
    LookupWebSvc.Credentials = CredentialCache.DefaultCredentials;
    LookupWebSvc.Url = Globals.ThisAddIn.LookupWebSvcURL;

    LookupTableWebSvc.LookupTableDataSet ds = 
        new LookupTableWebSvc.LookupTableDataSet();

    // Create a Filter object.
    PSLibrary.Filter cfFilter = new PSLibrary.Filter();
    // Restrict the filter to one table.
    cfFilter.FilterTableName = ds.LookupTables.TableName;

    // Add fields to the filter to limit the columns you want returned.
    // Set the sort order on the name column (optional for the Field constructor).
    cfFilter.Fields.Add(new PSLibrary.Filter.Field(ds.LookupTableTrees.TableName, 
    cfFilter.Fields.Add(new PSLibrary.Filter.Field(ds.LookupTableTrees.TableName, 

    PSLibrary.Filter.FieldOperator criteria = 
        new Microsoft.Office.Project.Server.Library.Filter.FieldOperator
        (PSLibrary.Filter.FieldOperationType.Equal, "LT_NAME", 
        new string[] { lookupTableName });

    cfFilter.Criteria = criteria;

    // The GetXml method creates the xmlFilter parameter for ReadCustomFields 
    ds = LookupWebSvc.ReadLookupTables(cfFilter.GetXml().ToString(), false, 0);

    return ds.Tables[0];

LookupTableWebSvc is a reference to the LookupTable web service on the Project server at _vti_bin/psi/lookuptable.asmx. Make sure to add this as a "Web Reference".

Copyright © 1997- 2020 Data Solutions