Home > Work > Prefill a list form field – External Data

Prefill a list form field – External Data

You may remember that the SharePoint Designer Team Blog in June 2007 wrote about how to manipulate List Form Fields in MOSS 2007 and WSS 3.0.  (Original Post)

In many of my projects we have to manipulate the list form fields on the newform.aspx and the editform.aspx for a variety of reasons, including:

  • Data Integrity
  • User Experience
    This post and many others in this series will go through how to pre-fill the various field types.

First off I shall start with what used to be one of the more advanced features in MOSS 2007 Enterprise but is now available as part of Business Connectivity Services in SharePoint Foundation and SharePoint Server 2010.

The External Data Field (formally the Business Data Field)

The standard way to pre-fill a BDC value in SharePoint 2007 was using the function below and this hasn’t changed in SharePoint 2010.

1 function getBDCTagFromIdentifierAndTitle(tagName, title, count) { 2 3 var tags = document.getElementsByTagName(tagName); 4 var myCount = 0; 5 6 for (var i=0; i < tags.length; i++) 7 { 8 var tempString = tags[i].id; 9 10 if (tags[i].title == title) 11 { 12 myCount++; 13 14 if(count == myCount) 15 { 16 return tags[i]; 17 } 18 } 19 } 20 21 return null; 22 23 }

However, what has changed in SharePoint 2010 is the title part of the function call.

1 function setBDCValue(prefillValue, bdcItemNumber) { 2 getBDCTagFromIdentifierAndTitle("TEXTAREA","External Item Picker", bdcItemNumber).value = prefillValue;//value; 3 getBDCTagFromIdentifierAndTitle("DIV","External Item Picker", bdcItemNumber).innerText = prefillValue;//value; 4 getBDCTagFromIdentifierAndTitle("A","Check if External Item exists", bdcItemNumber).onclick(); 5 }

The only change between 2007 and 2010 is the title section of each element within the External Data picker control.

  • TEXTAREA title: “External Item Picker”
  • DIV title: “External Item Picker”
  • A title: “Check if External Item exists”


You need to ensure that the functions “setBDCValue” & “getBDCTagFromIdentifierAndTitle” are available on the newform.aspx and / or the editform.aspx (please see future post regarding this).

You also need to gather the value you are trying to prefill.  This could be via the query string or some other method.

Once you have everything in place, the function call is as follows:

setBDCValue(prefillValue, bdcItemNumber)

  • prefillValue = String value to prefill the control
  • bdcItemNumber = the External Picker location on the page. 

I.E. if there are three External Data controls, inserting you prefill value into the 2nd control would be as follows:

  • setBDCValue(“Hello World”, 2);

You can use the function multiple times on the page if you need to prefill more than one control.

I hope all that makes sense, expect similar tutorials for the rest of the field types over the coming days / weeks.

  1. Andrew
    December 8, 2010 at 21:48

    Have you been able to get this to work with FireFox? Everything worked perfectly with Internet Explorer and Chrome but is not working in FireFox.

    The code has no problem finding the textarea, div and a tags but the values being set in setBDCValue do not show up in the picker.

    Also on a side note, I had to make sure the setBDCValue code ran on page load in order to work. Example is below if anyone runs into the same issue.

    function populatePickers()
    var val = getQueryStringValue(‘customerID’);

    function addLoadEvent(func)

    var oldonload = window.onload;
    if (typeof window.onload != ‘function’)
    window.onload = func;
    window.onload = function()
    if (oldonload)

    • December 13, 2010 at 13:55

      looking at this just now I can confirm that this does not work in FireFox, I will update the post when I get the chance.

      Kind Regards


  2. Andrew
    December 21, 2010 at 21:27

    It seems to be a difference in the DOM between browsers. You just need to also set ‘innerHTML’ on the tag as well. So my code change is as such:

    function setBDCValue(prefillValue, bdcItemNumber) {
    var div = getBDCTagFromIdentifierAndTitle(“DIV”,”External Item Picker”, bdcItemNumber);
    div.innerHTML = prefillValue;//HANDLES FIREFOX
    div.innerText = prefillValue;//HANDLES IE AND CHROME

    getBDCTagFromIdentifierAndTitle(“TEXTAREA”,”External Item Picker”, bdcItemNumber).value = prefillValue;

    getBDCTagFromIdentifierAndTitle(“A”,”Check if External Item exists”, bdcItemNumber).onclick();

  3. April 18, 2012 at 17:42

    Giles – can you post a full SP 2007 BDC sample? I have followed your links to the older posts, and can’t quite get a handle on it. I would love to have a way to 1. read a value in an existing Business Data field on a form, and 2. Change or prefill the value.

    Any guidance is appreciated!

    • April 19, 2012 at 08:10

      Thanks for your comments Bill.

      I have sent you an email so we can take this offline. Once we get to an answer, I will can post the result online.

      Kind Regards


  4. KJ
    December 19, 2012 at 16:50

    Would love to see someone get the autocomplete Jquery function working with the External Item Picker.. anyone? Being able to see autocomplete values as someone types in a BCS control would be great.

    The only solution I can muster is to hide the BCS field, create a second input field, attach an autocomplete to it, and then bind the change() on that field to then update the hidden BCS field.

    • December 19, 2012 at 23:31

      Hi KJ,

      We have never implemented such things on a BCS control either. The method you are suggesting would work. You could even attach the suggestions pop up to the existing div rather than creating a new control.

      Just a thought…


  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: