Function

$().SPServices.SPLookupAddNew

Functionality

The SPLookupAddNew function allows you to provide a link in forms for Lookup columns so that the user can add new values to the Lookup list easily. It is based on a blog post by Waldek Mastykarzv (see Credits). The function works like this:
  1. Uses GetList for the current list to determine the details for lookupColumn
  2. Uses GetList for the Lookup column's list to determine the list's URL
  3. Uses GetFormCollection to get the URL for the NewItem form for the Lookup column's list
  4. Appends the link to the Lookup columns's formbody table cell using the promptText provided

Prerequisites

  • The form displays a Lookup column.

Syntax

$().SPServices.SPLookupAddNew({	
	lookupColumn: "",		// The DisplayName of the Lookup column
	promptText: "Add new {0}",	// Text to use as prompt + column name
	debug: true		// [Optional] If true, show error messages; if false, run silent
});

By StaticName, we mean the underlying column name, e.g., Region_x0020_Name. The DisplayName would be Region Name, i.e., the name of the column which is shown on the form.

Setting debug: true indicates that you would like to receive messages if anything obvious is wrong with the function call, like using a column name which doesn't exist. I call this debug mode. As with all of the functions in the library, this function "runs silent", meaning that no messages or alerts are presented to the user if something goes wrong. This means that no inherent functionality is lost due to a problem. By using debug mode, you can receive messages to help you get things set up; I recommend turning debug mode off once everything is in place and running correctly.

Example

$(document).ready(function() {
	$().SPServices.SPLookupAddNew({	
		lookupColumn: "Region Name",
		promptText: "Add new {0} "
	});
});


The prompt in this example will be 'Add New Region Name'. Other prompt examples:
'Add {0}' --> 'Add Region Name'
'Enter a new {0} if you want' --> 'Enter a new Region Name if you want'
'Add one' --> 'Add one' (by not providing the {0} placeholder, the lookupColumn name is not displayed)
Last edited Nov 12 at 5:34 AM by sympmarc, version 12
Comments
ryan227 Oct 26 at 7:50 PM 
Hey there, I was able to get the SPCascadeDropdowns function to work on my custom form using Sharepoint Designer, but nothing happens when I try to use the SPLookupAddNew for one of the lookup columns in the form. That is, is there anything else to be done example modifying the example code?

sympmarc Nov 8 at 12:06 AM 
Ryan:

I just saw your comment by chance. You should use the discussions to ask questions as there is no email notification from here. There's a bug in this function when there are 20+ options in the dropdown. I've got a fix coming in v0.5.0 but I can send it to you if you need it sooner. Let me know.

M.

Updating...
© 2006-2009 Microsoft | About CodePlex | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2009.10.27.15987