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 (5)

  1. Yoni says:

    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

  2. lduff says:

    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.

  3. RG says:

    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.

  4. DGR says:

    Hi,

    Thanks a lot for the solution.

    It bugged me for a while ..

    It works fine now, with the language id 0.

  5. Jorge says:

    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!

Skip to main content