SPRequireUnique how to return result

Jul 12, 2011 at 2:41 AM
Edited Jul 12, 2011 at 2: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 11:21 AM


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 7: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 4:15 PM