This project has moved. For the latest updates, please go here.

Advice on setting SPFieldUser field

Oct 20, 2014 at 9:50 PM
Recognizing the fact that manipulating a field of type SPFieldUser is apparently still considered "experimental", looking to see if anyone has found a way that it might work.

I'm trying this code with SharePoint 2013:
        var currentUser = $().SPServices.SPGetCurrentUser({
            fieldNames: ["UserName","Title"],
            debug: false
        });
        SPUtility.GetSPField('Requester').SetValue(currentUser.Title);
This results in the following JavaScript error:

SCRIPT5007: Unable to get value of the property 'AddUserKeys': object is null or undefined
sputility.min.js, line 10 character 9005

And the form field in question is not changed. Just sanity checking whether I might be doing something not quite right and it really can work, particularly since the examples on the home page for this site (https://sputility.codeplex.com/) includes the example "Set a People field and/or Make it Read Only" which implies that it should.

Thanks!
Coordinator
Oct 21, 2014 at 8:44 PM
Hey shawnc1959,
Sorry for the confusion... this is a problem with SPUtility.js - not your form. I will update the home page and remove the SPUser field example.

Some background: SPUtility.js used to specifically target only SharePoint 2007 where I was able to get the code working for getting/setting people fields. Then, I migrated the code to jQuery and also started supporting SharePoint 2010 and 2013. The people fields in these new(er) versions of SharePoint are much different and I have not been able to get this feature working again.

If you are comfortable with JavaScript, you can take a look at the SPUserField class (specifically the part with SPClientPeoplePicker):
https://github.com/kitmenke/sputility/blob/master/src/sputility.js#L1486

Also, haven't looked into it yet but there is some more info here: https://github.com/kitmenke/sputility/issues/3

If you figure something out let me know and I'll add it.
Thanks,
Kit