SPRequireUnique method relying on default list view?

Feb 12, 2010 at 10:32 AM

Hi Marc,

I've been using the SPRequireUnique method for a while now and it's been fine, everyone thinks its great. I recently had to implement it on a different list and got some strange results in that it would only work for items I had entered on the list. On investigation I narrowed it down to the fact that we had a custom view setup as the default view for that list and it happened to have a [me] filter on it.

So it seems that the unique check is only looking at the default (filtered) view rather than the whole list. Could you confirm/deny and even better offer a solution please?

Many thanks,

Paul

Coordinator
Feb 12, 2010 at 1:25 PM

Paul,

The SPRequireUnique method uses a GetListItems web service query to return the column defined in the call, so I don't believe it would be affected by the view. Which version of SPServices are you using?

Mike

Feb 12, 2010 at 1:49 PM

Mike,

The column is available in all views but the situation is very repeatable. Using the method as I've done many times before, with the "All Items" view set as the default, it works fine. Any item that exists in the list is trapped and we're all happy. If I then change the default view of the list to a custom view which has a filter on it, the the RequireUnique method fails to find it (on the newform).

I'm using 0.5.0 and JQuery 1.4.1

Thanks,

Paul

Feb 12, 2010 at 2:13 PM

Ok, so further investigation lead me to looking at the underlying call, the GetListItems method (http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems.aspx) it seems that if you don't explicitily provide a view name, it will use the default view. So there it is, that's the problem.

So the question is, how can I add a view name to the SPRequireUnique method?

Thanks,

Paul

Coordinator
Feb 12, 2010 at 2:36 PM

Paul,

Nice find. I just got an email from Marc--he's off at SPTechCon in San Francisco, but he's going to take a look at this for you.

Mike

Coordinator
Feb 12, 2010 at 2:46 PM

Paul:

This does indeed look like a bug.  I think that the quick fix for you will be to create a view which shows all items and pass the GUID of the view in the GetListItems call in SPRequireUnique, as below.  Obviously, this isn't a very good fix for you, so I'll try to get a real one into the next alpha of 0.5.1 ASAP.

M.

// Call the Lists Web Service (GetListItems) to see if the value already exists
   $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: listNameFromUrl(),
    viewName: "YourViewGUID", // <------------------ Your view GUID here.
    // Filter based on columnDisplayName's value
    CAMLViewFields: "<ViewFields><FieldRef Name='" + columnDisplayName + "' /></ViewFields>",
    // Override the default view rowlimit and get all appropriate rows
    CAMLRowLimit: 0,
    completefunc: function(xData, Status) {
     var testValue = opt.ignoreCase ? columnValue.toUpperCase() : columnValue;
     $(xData.responseXML).find("[nodeName=z:row]").each(function() {
      var thisValue = opt.ignoreCase ? $(this).attr("ows_" + opt.columnStaticName).toUpperCase() : $(this).attr("ows_" + opt.columnStaticName);
      if(testValue == thisValue) columnValueCount++;
     });
    }
   });

 

M.

Feb 12, 2010 at 4:19 PM

Thanks Marc & Mike,

Thank will do me perfectly until the next version comes out. Thank you very much for the super quick responses.

Cheers,

Paul

Coordinator
Feb 14, 2010 at 10:27 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Feb 15, 2010 at 3:09 AM

Paul:

In case you aren't alerted by the Issue Tracker, I've just released v0.5.1ALPHA3 with a fix for this issue. Give it a try and let me know if it works for you.

M.