Populating BDC fields from a query string in MOSS (Microsoft Office Sharepoint Server) 2007

Whomever tried to populate a MOSS (Microsoft Office Sharepoint Server) form field using Javascript noticed that it is far from being straightforward. The secret is in the undocumented core.js After a client's request I was able to come up with a not so-intrusive Javascript solution.

You have to open the site in Sharepoint Designer, navigate to the list you want (in my example I used a list called "Public Details"), look for a spot in the html code and copy the Javascript code below to both EditForm.aspx and NewForm.aspx.

For each list in your site there will be a folder. For instance, let’s say you have a list called Public Details. In Sharepoint Designer you should edit files under site\Lists\Public Details as shown below (be aware these pages will be unghosted after that):


To test the application, just add the query string ?BDC=<value> to the url (eg. http://portal/Lists/Public+Details.aspx?BDC=123). See code below:


<script type="text/javascript" language="javascript" for="window" event="onload">

var elems = document.getElementsByTagName("DIV");var bdcString="";

var queryString = document.location.search.split("&");

for (var i=0;i<queryString.length;i++) {if ((queryString[i].split("=")[0]=="BDC") || (queryString[i].split("=")[0]=="?BDC")) bdcString=queryString[i].split("=")[1]; }

if(bdcString == "") return;

for (var i=0;i<elems.length;i++) {

if (elems[i].id.indexOf("_upLevelDiv") > 1){ var subs = elems[i].id.substring(0,elems[i].id.indexOf("_upLevelDiv")); var upLevel = document.getElementById(subs+"_upLevelDiv"); if(upLevel == null) { alert("error Up Level is invalid: "+subs+"\n"+upLevel); return; } var downlevel=document.getElementById(getSubControlID(subs, g_EntityEditorDownLevelId)); downlevel.value = bdcString; var editor=document.getElementById(subs) SetInnerText(upLevel, bdcString); copyUplevelToHidden(subs); }}