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.

Comments

  • Anonymous
    September 10, 2006
    The comment has been removed

  • Anonymous
    September 14, 2006
    WebSvcLookupTable is a reference to the LookupTable web service.  You need to create a web reference to the lookup table web service called WebSvcLookupTable and instaniate it for the code to work.

  • Anonymous
    January 04, 2007
    I'm trying to filter the lookup dataset using the filter class, I've done the filtering with a single criteria just as shown above and it works. Now I'm trying to filter like an "in" clause in SQL. I'm trying to use the Within operation type does this should work? I've tried without sucess. Does anyone has an example. BTW, I'm looking for an example using the logical operators, but I have not find anything yet, does anyone has an example. I would appreciate, it you can help me with this.

  • Anonymous
    July 07, 2008
    Hi, Thanks a lot for the solution. It bugged me for a while .. It works fine now, with the language id 0.

  • Anonymous
    March 18, 2009
    THANK YOU!!  I've been racking my brain as to why my filter wasn't working.  I would have never guessed it was the language id.  You rule!