Archive

Posts Tagged ‘Prefill List Form’

Useful JavaScript Function: Retrieve Query String Value

October 11, 2010 Leave a comment

Quite often during my implementations I need to retrieve values from the query string to use as prefill values or perhaps redirect users to another page where I am using the Query String URL Filter.

1 function querySt(ji) { 2 hu = window.location.search.substring(1); 3 hu = hu.toLowerCase(); 4 gy = hu.split("&"); 5 6 for (i=0;i<gy.length;i++) { 7 ft = gy[i].split("="); 8 9 if (ft[0] == ji) { 10 return ft[1]; 11 } 12 13 } 14 15 return ""; 16 }

Usage:

  • Parameter: String – in lowercase (to avoid any confusion or mismatches)
  • querySt(“string”);

For Example:

URL: http://servername/pages/test.aspx?ProjectID=PRJ0001

To retrieve the ProjectID value call the function as follows:

  • querySt(“projectid”);
Advertisement

Prefill a list form field – External Data

October 11, 2010 7 comments

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”

Usage:

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.

%d bloggers like this: