Reading a Lookup Table

In the spirit of the custom field discussion the other day, how about a little blurb on Lookup Tables? Someone sent me some fairly straightforward code that was throwing an exception. Here is the code:

try

{

WebSvcLookupTable.LookupTable LookupTableWebservice = new

ChangeRTF.WebSvcLookupTable.LookupTable();

LookupTableWebservice.CookieContainer = new CookieContainer();

LookupTableWebservice.Credentials = CredentialCache.DefaultCredentials;

LookupTableWebservice.Url = server + "/_vti_bin/psi/lookuptable.asmx";

WebSvcLookupTable.LookupTableDataSet dsLookup =

new WebSvcLookupTable.LookupTableDataSet();

Filter lookupFilter = new Microsoft.Office.Project.Server.Library.Filter();

String TableName = dsLookup.LookupTables.TableName.ToString();

lookupFilter.FilterTableName = TableName;

lookupFilter.Fields.Add(new Filter.Field(TableName,

dsLookup.LookupTables.LT_NAMEColumn.ColumnName));

lookupFilter.Fields.Add(new Filter.Field(TableName,

dsLookup.LookupTables.LT_UIDColumn.ColumnName));

Filter.FieldOperator criteria = new

Microsoft.Office.Project.Server.Library.Filter.FieldOperator

(Filter.FieldOperationType.Equal, "LT_NAME", new string[] { "Project Status" });

lookupFilter.Criteria = criteria;

dsLookup = LookupTableWebservice.ReadLookupTables(lookupFilter.GetXml().ToString(),

false, 1033);

}

catch (System.Web.Services.Protocols.SoapException SoapEx)

{

MessageBox.Show(SoapEx.Message);

}

The issue is when you get down to the ReadLookupTables methods you fail with an exception LookupTableLanguageParameterInvalidWithXmlFilter. All the parameters are correct, I can even tell you that the Filter is 100% correct (filters are still a bit of a black art so that is where I thought the problem was). Amazingly the problem is actually with parameter verification, but undocumented (i.e. I had to look at the source code to figure out the problem.) If you specify a filter you cannot specify a language code other than zero. The following call will work:

dsLookup = LookupTableWebservice.ReadLookupTables(lookupFilter.GetXml().ToString(),

false, 0);

Or if you really don’t care about a filter the following would also work:

dsLookup = LookupTableWebservice.ReadLookupTables(string.Empty, false, 1033);

Hope this allows some of you to miss this pothole.