Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 21st, 2013, 06: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!
  #2 (permalink)  
Old January 23rd, 2013, 09: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/
The Following User Says Thank You to ScotHillier For This Useful Post:
richv (January 25th, 2013)
  #3 (permalink)  
Old January 25th, 2013, 12:20 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 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();
                }

            }


        }
    }


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 06:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.