This project has moved and is read-only. For the latest updates, please go here.

SPRequireUnique how to return result

Jul 12, 2011 at 3:41 AM
Edited Jul 12, 2011 at 3:44 AM
var result;
	columnStaticName: "userIDstring",
	duplicateAction: 1,
	ignoreCase: false,
	initMsg: "This person must be unique.",
	initMsgCSSClass: "ms-vb",
	errMsg: "This person has already been added.",
	errMsgCSSClass: "ms-formvalidation",
	showDupes: true,
	completefunc: function() {
		// Not sure how to do this
		if (unique) {
			result = 1;
		else if (!unique) {
			result = 0;

Is there a way to store the result of the comparison (unique or not unique) in completefunc?

Jul 12, 2011 at 12:21 PM


The completefunc is only called once when you originally call the SPRequireUnique function. I included it there just in case you'd want to do some sort of alteration to the messages or something which I didn't support in the options. completefunc is not called when you attempt to set a value in columnStaticName.

You could attach your own function to the blur event or clone SPRequireUnique to meet your needs.


Jul 12, 2011 at 8:50 PM

Thanks Marc.  I cloned SPRequireUnique below

// Check to see if there is a duplicate
var camlQuery = "<Query><Where><Eq><FieldRef Name='userID' /><Value Type='User'>" + userID + "</Value></Eq></Where></Query>";
var userMatch;
	operation: "GetListItems",
	async: false,
	listName: "Employees",
	CAMLQuery: camlQuery,
	completefunc: function (xData, Status) {
			userMatch = $(this).attr("ows_userID");

// If there is a duplicate
if (userMatch != undefined) {

// Else if there is not a duplicate
else if (userMatch == undefined) {
	alert("No match");

Jul 13, 2011 at 5:15 PM