Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Business Connectivity Services in SharePoint 2010 by Scot Hillier, Brad Stevenson
This is the forum to discuss the Wrox book Professional Business Connectivity Services in SharePoint 2010 by Scot Hillier, Brad Stevenson; ISBN: 978-0-470-61790-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Business Connectivity Services in SharePoint 2010 by Scot Hillier, Brad Stevenson section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 1st, 2013, 05:34 PM
Authorized User
Points: 95, Level: 1
Points: 95, Level: 1 Points: 95, Level: 1 Points: 95, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2010
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
Default Querying an external list.

Hey all...
I'm attempting to grab the BDCIdentity value from my PartLookup field (lookup to an external list) and retrieve the SPListItem that corresponds to this site column's value on the current SPListItem in the child list. You figure that would be fairly simple. It is turning out to be quite painful.
I tried to use a bunch of different approaches and none seem to work.

So, the goal actually is in an ItemAdding event receiver, for the current affected SPListItem, grab the BDCIdentity value (ie '__bg#######) and locate the corresponding SPListItem in the external list. I actually need to retrieve another field value for that list.

Anyway, here is the final version of my code and I'm in a simple console app. I'm logged into the SharePoint Server as the farm account when I'm executing the code.


Code:
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite(_sSiteURL))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    Console.WriteLine("Site: " + site.Url);

                    SPList partList = null;

                    foreach (SPList lList in web.Lists)
                    {
                        if (lList.RootFolder.Name == "PartList")
                        {
                            partList = lList;
                            break;
                        }
                    }
                    
                    SPQuery query = new SPQuery();
                    query.Method = "<Method Name='GetAllPartEntitys'><Filter Name='Description' Value='{0}'/></Method>";
                    query.ViewFields = "<FieldRef Name='BdcIdentity'/><FieldRef Name='sName'/>";
                    query.Query = "<Where><Contains><FieldRef Name='sName'/><Value Type='Text'>HP</Value></Contains></Where><OrderBy><FieldRef Name='BdcIdentity'/></OrderBy>";
                    SPListItemCollection foundItems = partList.GetItems(query);
                    Console.WriteLine(String.Format("Count of FoundItems: {0}", foundItems.Count));

                }

            }

        }

When the code gets to the final Console.WriteLine, it throws the following exception:

Code:
System.UnauthorizedAccessException was unhandled
  Message=Attempted to perform an unauthorized operation.
  Source=Microsoft.SharePoint
  StackTrace:
       at Microsoft.SharePoint.SPListDataSource.CheckUserIsAuthorized(SPBasePermissions perms)
       at Microsoft.SharePoint.SPListDataSource.GetFilteredEntityInstances(XmlDocument xdQueryView, Boolean fFormatDates, Boolean fUTCToLocal, String firstRowId, Boolean fBackwardsPaging, String& bdcidFirstRow, String& bdcidNextPageRow, List`1& lstColumnNames, Dictionary`2& dictColumnsUsed, List`1& mapRowOrdering, List`1& lstEntityData)
       at Microsoft.SharePoint.SPListItemCollection.EnsureEntityDataViewAndOrdering(String& bdcidFirstRow, String& bdcidNextPageFirstRow)
       at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()
       at Microsoft.SharePoint.SPListItemCollection.get_Count()
       at SetExternalLookupField.Program.Main(String[] args) in C:\source\Blackcreek\SharePointUtils\SetExternalLookupField\SetExternalLookupField\Program.cs:line 66
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
I can browse the rows in external list without a problem. This same code will also not run under the event receiver.


Please note that I also attempted to use the caml syntax from Page 143 in the book. Same result.

Also, the final iteration of the approach I attempted is from this site.http://sharepoint.stackexchange.com/...-finder-method

Last edited by richv; February 1st, 2013 at 05:36 PM. Reason: Added more detail.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
AddDependentLookup and external list lookup columns. richv BOOK: Professional Business Connectivity Services in SharePoint 2010 by Scot Hillier, Brad Stevenson 0 February 1st, 2013 01:45 PM
Problem setting the value of an external list lookup column. richv BOOK: Professional Business Connectivity Services in SharePoint 2010 by Scot Hillier, Brad Stevenson 2 January 25th, 2013 11:20 AM
The created external list does not support updating existing items Treffe BOOK: Beginning SharePoint 2010 Development 5 August 2nd, 2010 11:56 AM
Permissions issue on Create External List - resolved kendo666 BOOK: Beginning SharePoint 2010 Administration: Windows SharePoint Foundation 2010 and Microsoft Sha 0 July 27th, 2010 09:26 AM
Querying external Excel datafile from excel utalwalk Excel VBA 1 March 30th, 2006 11:47 AM



All times are GMT -4. The time now is 09:38 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.