Welcome to MSDN Blogs Sign in | Join | Help

Larry's Project Dev Blog

The musings of developing for Microsoft Project.
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.

Posted: Friday, June 30, 2006 4:12 PM by lduff

Comments

Yoni said:

Hello,

I'm trying to read a look up table, but i don't succeed.

the problem is that he cannot recognize WebSvcLookupTable.
when i put this line
public  LookupTableWebservice as WebSvcLookupTable.LookupTable = new ...

Vs underline and tell me that ebSvcLookupTable.LookupTable is not defined !

Wich dll are needed ? i have those one
Microsoft.SharePoint
Imports PSLibrary = Microsoft.Office.Project.Server.Library

If someone can help it will be gratefull

thank you in advance
yonialhadeff@gmail.com
# September 11, 2006 7:10 AM

lduff said:

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.
# September 14, 2006 1:12 PM

RG said:

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.

# January 4, 2007 7:28 PM

DGR said:

Hi,

Thanks a lot for the solution.

It bugged me for a while ..

It works fine now, with the language id 0.

# July 7, 2008 5:12 PM

Jorge said:

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!

# March 18, 2009 7:28 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker