jQuery Library for SharePoint Web Services (SPServices) v0.7.2 Released

Today I’m releasing SPServices v0.7.2. If you are using an earlier version of SPServices, I suggest that you upgrade to this version, as you will most likely see some performance improvements, especially if you use multiple value-added functions on the same forms pages.

Thanks to everyone who downloaded the beta over the last month or so and provided feedback. The most important piece of feedback I received was an incompatibility with jQuery 1.8.x, which I was able to fix and get into this release.

Caching

I’ve added a caching option into this version of SPServices and it can save a decent amount of traffic back and forth with the server, depending on how you are using things. It uses jQuery’s .data() functions to cache the XML for each request which has the option cacheXML: true. This is basically brute force. If cacheXML: true, then the returned XML is saved as a data object on the body of the page with the request XML as the key. If you make the exact same call again, then the request is fulfilled from that cache. Note that it has to be the “exact same call”. This means that the request XML has to match exactly.

I’ve set the option to true for some of the internal calls to the Web Services operations to speed things up when you use functions multiple times. For instance, quite a few of the value-added functions make a call to GetList to get details about the current list, and there’s no need to make that call more than once during the page life. If you are creating more than one cascade with SPCascadeDropdowns, for example, you’ll see an immediate improvement. However, since I can’t predict how many values you may have coming back from GetListItems calls, I haven’t turned on caching pervasively. I didn’t want to break things in an effort to be more efficient. Some client machines may not have the horsepower to cache large volumes of data, etc. If you know your data and your client machine capabilities well, you can set the option to true in the defaults – $().SPServices.defaults.cacheXML = true; – which will affect all Web Service operation calls in the current page lifecycle.

You can use the cacheXML: true option with any Web Service operation in SPServices Core, though as you can imagine some operations will benefit more than others.

SPFindPeople Picker

The SPFindPeoplePicker function helps you find and set People Picker columns. These little buggers are problem enough as it is, and selecting them and manipulating them with jQuery is something that a lot of people want to do. Add to that the fact that the People Picker is rendered differently in IE than in other browsers, and you have a challenge not unlike simple vs. complex dropdowns.

SPFindPeoplePicker allows you to get or set the values for People Pickers. When you call it with the DisplayName of a People Picker, the function returns an object which contains information about the People Picker’s structure nd current value. For instance, calling the function like this:

var salesRep = $().SPFindPeoplePicker({
  peoplePickerDisplayName: "Sales Rep",
  valueToSet: "APPTIXemullerbeck53"
});

returns an object which contains the following:

SPFindPeoplePicker Object

peoplePickerDisplayName

The DisplayName of the People Picker in the form.

row

This is reference to the table row which contains the People Picker. This can be useful if you want to hide or show the row conditionally based on some user action.

contents

The full contents of the div[name='upLevelDiv'] element.

currentValue

The current value set in the People Picker. If you pass a value into the function, it will be set and returned in this string. If there are multiple people specified, they are returned separated by semicolons, as in the People Picker display.

checkNames

This is a reference to the checkNames img tag in the People Picker. It’s used by the function to initiate resolution of a Person or Group value by firing the click event on it. Once you have this reference, you can do the same.

dictionaryEntries

If the browser is Internet Explorer, then this object will contain the full dictionary entry values for each user or group in the People Picker value. If the browser is not IE, then the function calls GetUserInfo to retrieve similar values to mirror the dictionary entry structure.

Other Release Notes

There are other goodies in this release, and you can see the full list of enhancements and improvements on the download page. Note the link to the Issue Tracker items for this release.

For posterity, the release notes are included below. You can check out all the changes (the release pages have a character limit for the release notes) in the Issue Tracker.

New Functionality

Alpha Issue Tracker Item Function Operation Description
ALPHA1 10071 $().SPServices.SPXmlToJson NA Enhanced userToJsonObject for use when ExpandUserField = True
ALPHA3 10074 $().SPServices.SPFindPeoplePicker NA Add SPFindPeoplePicker Function
ALPHA4 10070 $().SPServices.SPXmlToJson NA SPXmlToJson – calculated fields and “blank” xml attributes
ALPHA5 9969 $().SPServices.SPGetStaticFromDisplay and $().SPServices.SPGetDisplayFromStatic NA Getting multiple columns in one SPGetStaticFromDisplay call

ALPHA3 – Added caching capability to the SPServices core AJAX function to make it available across all SPServices value added functions and Web Services operations.

ALPHA7– Fixes to SPFindPeoplePicker to work with non-IE browsers.

New Operations

Alpha Web Service Operation Options MSDN Documentation Issue Tracker Item
ALPHA1 Diagnostics SendClientScriptErrorReport message, file, line, client, stack, team, originalFileType SharePointDiagnostics.SendClientScriptErrorReport Method 10028
ALPHA2 People ResolvePrincipals principalKeys, principalType, addToUserInfoList People.ResolvePrincipals Method 10062
ALPHA5 Lists AddListFromFeature listName, description, featureID, templateID Lists.AddListFromFeature Method 10064
ALPHA5 SpellCheck SpellCheck chunksToSpell, declaredLanguage, useLad SpellChecker.SpellCheck Method 10063
ALPHA5 Lists various NA see work item 9884

ALPHA2 – Added these Sites Web Service operations: CreateWeb, DeleteWeb, GetSite, GetSiteTemplates

Bug Fixes and Efficiency

Alpha Issue Tracker Item Function Description
ALPHA1 10061 $().SPServices.SPDisplayRelatedInfo Not Properly Handling UserMulti Columns
ALPHA1 9926 $().SPServices.SPCascadeDropDowns ‘&’ symbol values
ALPHA1 9925 NA dropdownCtl bug in Italian Sites
ALPHA5 9931 $().SPServices.SPGetLastItemId missing reference

Similar Posts

20 Comments

    1. Gabe:

      The SPAutocomplete function is built to only work with Single line of text columns. You could certainly use jQueryUI’s autocomplete function. However, People Pickers are tricky little beasties.

      Why wouldn’t you just use the People Picker as is if you want to draw from SharePoint users?

      M.

  1. Hi Marc,
    I have set cacheXML to true and it works fine until the list is updated. After the cache doesn’t seem to be refreshed.
    A workaround could be to force data to be retrieved again with caching set to false once they have been updated but that’s not completely satisfying.

  2. Just an FYI…SPFindPeoplePicker is not a supported method for a “Person/Group” column in SharePoint. Do you have a control we can add to our farm that can be used in place of a Person or Group field where the SPFindPeoplePicker method can be applied? Thanks,

  3. This worked great BUT I can’t set focus() on the people picker. Can someone help me with the code for that.

    var salesRep = $().SPFindPeoplePicker({
    peoplePickerDisplayName: “Sales Rep”,
    valueToSet: “APPTIXemullerbeck53”
    });

    i tried adding:
    salesRep.row.find(“textarea[id$=’_downlevelTextBox’]”).focus();
    or salesRep.row.focus();

    neither worked for me.

    1. Rob:

      This just worked for me:

      var salesRep = $().SPFindPeoplePicker({
        peoplePickerDisplayName: "Sales Rep",
        valueToSet: "APPTIX\\mullerbeck53"
      });
      salesRep.row.find("div[title='People Picker']").focus();
      

      M.

  4. Hi Can I use SPFindPeoplePicker method to get peoplepicker’s value?

    and I try like this
    function GetPeopleo()
    {
    var salesRep = $().SPFindPeoplePicker({
    peoplePickerDisplayName: “”

    });

    var currentValue=salesRep.currentValue;

    it same does’t work . thanks

    1. jhy5188:

      It doesn’t look like you’re passing the DisplayName into the function. It should look like this:

      function GetPeopleo()
      {
      var salesRep = $().SPFindPeoplePicker({
      peoplePickerDisplayName: "columnName"

      });

      var currentValue=salesRep.currentValue;

      where columnName is the DisplayName of your column.

      M.

  5. Hi Marc,
    I am trying to get the people picker field (in my case ‘Forward To’) value using SPFindPeoplePicker, but everytime I am getting an empty value. And it showing empty dictionaryentries. Please find below my code, here before saving the list data I want to confirm the user if “Forward To” field is empty.

    function PreSaveAction(){

    var forwardTo = $().SPFindPeoplePicker({
    peoplePickerDisplayName: “Forward To”,
    checkNames: false
    });
    var forwardValue= forwardTo. currentValue;
    If(forwardValue!=””){
    return true;
    }else{
    var userResp=confirm(“Forward To is empty. Do you really want to Save It?”);
    return userResp;
    }
    }

    It will be really helpful if you can help me to figure out what I have missed. Thanks in advance.

    //ahsan

  6. what about oberation: addusertogroup? is it existed in spservices 0.7.2? coz i was trying something like this and not working ?? $().SPServices({

    operation: “AddUserToGroup”,
    groupName: “Social Committee”,
    userLoginName:”domain\user”,
    async: false,
    completefunc: null
    });

    }

  7. Hi March,
    I am using in SharePoint 2013, the people picker value is not populating. Can you help me please. Below is the code:

    $(document).ready(function() {
    var salesRep = $().SPFindPeoplePicker({
    peoplePickerDisplayName: “Observer(s)”,
    valueToSet: “Asiapacific\\sahoobij”
    });
    });

  8. Hi Marc, thanks for the code. However, $().SPFindPeoplePicker({}); doesn’t work for Multi user PP. Please provide some alternatives to get user id from PP having multiple user.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.