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 January 21st, 2013, 05:52 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 Problem setting the value of an external list lookup column.

Hello all...

I have an external list (based on ECT of course). The list is working great with no problems.
I have created a lookup column based on that external list and attached it to a standard SharePoint list.
All is working with, with one exception.
I need to set the value of the external lookup column programmatically.

I cannot seem to find an example of this.

To summarize, I'm trying to set the value of the external lookup column programmatically on my secondary list.

External List: Customers
External List Lookup Column: CustomerLookup

Standard SharePoint List: Job List
Columns: Title (standard SP Title), JobDate (standard Date Time column), CustomerLookup (lookup column from above).

How do I set the value of the item?

SPListItem item = ....
item["Title"]= "My Text";
item["JobDate"] = somedatevalue;
item["CustomerLookup"] = ??????

Thanks in advance!
Reply With Quote
  #2 (permalink)  
Old January 23rd, 2013, 08:17 AM
Wrox Author
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2011
Posts: 3
Thanks: 0
Thanked 2 Times in 2 Posts
Default Setting Value of External Column

http://rompenpatrick.wordpress.com/2...l-data-column/
Reply With Quote
The Following User Says Thank You to ScotHillier For This Useful Post:
richv (January 25th, 2013)
  #3 (permalink)  
Old January 25th, 2013, 11:20 AM
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 Thanks for the hint...

Works great Scott. Thanks for taking the time.

Using the URL, I managed to get it working easy enough. Some of the code from the URL was misleading, so I am putting the code sample here, slightly modified with a little more description.

Code:
class Program
    {

        private static string _sSiteURL = @"http://mysharepointserver/sites/renewals2/sub";

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

                    SPList list = web.Lists["TestList"];
                    SPListItem spItem;

                    spItem = list.Items.Add();
                    spItem["Title"] = "My Test Title";

                    // Get a reference to the lookup field
                    SPField myField = spItem.Fields["Customer Lookup"];  // "Customer Lookup" is the display name of the field

                    String lsBCSRelatedFieldName = myField.RelatedField;  // get the name of the actual primary key related field
                    
                    //Set the Entity Instance value
                    int id = 11662;
                    spItem[lsBCSRelatedFieldName] = EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { id });
                    //Set the field display value * Please note that the display value is actually unnecessary and can be set with anything.
                    // this will get overwritten eventually from the external content type.
                    spItem["Customer Lookup"] = "Some customer name value.";

                    spItem.Update();
                    list.Update();
                }

            }


        }
    }
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
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
Excel/VBA Multi-Column Lookup - Round 2 RollingWoodFarm Excel VBA 4 August 3rd, 2006 07:28 PM
DTS - Multiple Column Lookup Problem asimahmed SQL Server DTS 2 April 4th, 2006 01:58 PM
Setting Column Width r_ganesh76 Excel VBA 2 February 2nd, 2005 05:06 AM



All times are GMT -4. The time now is 08:14 PM.


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