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. https://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); }} </script> |
Comments
Anonymous
July 06, 2008
Hi, Could you please let me know, How to access data from BDC in javascript?Anonymous
July 07, 2008
The comment has been removedAnonymous
January 31, 2009
Rodney, This is just what we were looking for to resolve passing a bdc in a query string. We have run into some issues. Would you be able to recommend a consulatnat who could assist us in this area. Thanks PennyAnonymous
February 19, 2009
This is just brilliant :-) it is working perfect! /ChristianAnonymous
February 25, 2009
Re: Penny's question about consultanting assistance: If you are in the Dallas area, there is a great gathering of Sharepoint talent at the DFW Sharepoint user group (http://www.dfwsharepoint.com/). My firm, Integrated Services, Inc. (www.isi85.com) facilitates the user group, and of course would be happy to assist you as well. My email address is garyc at isi85.com (fix the preceding text to be proper email format). Best regards, Gary CogginsAnonymous
May 14, 2009
Olá, estou passando aqui no Blog pra mandar um alô, e como está aí? tudo bem? ah to começando a fazer o blog de sharepoint, e adicionei lá nos blogs relacionados o seu ta ok? abraços