1

I have researched this pretty thoroughly and everyone says that the code I have below should load SP.js, but I cannot get it to load.

Debugging I get:

NewForm.aspx, line 1667 character 5
SCRIPT5009: 'PeoplePicker' is undefined 

and do not see SP.JS under view sources.

<SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" 
    Localizable="false" /> 
<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded(SetWebUserData(), "SP.js");

function SetWebUserData() {
    var pplPicker = new PeoplePicker();
    // Set the parent tag id of the people the picker.
    pplPicker.SetParentTagId('Main_x0020_Contact');
    pplPicker.SetLoggedInUser();
    };
</script>

Any assistance greatly appreciated.

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
user2366475
  • 31
  • 1
  • 1
  • 3
  • `SP.js` is loading fine. The error is stating that you haven't defined the class `PeoplePicker`. If you have, then there's an error with that class or the script in which it is defined is not loading properly. – Elliot Bonneville May 09 '13 at 14:04
  • I have defined PeoplePicker in the SP.js file and even when I delete all the code and just make PeoplePicker an alert function, I get no alert. I do not beleive that sp.js is loading fine. – user2366475 May 09 '13 at 14:19
  • If I include PeoplePicker in the source code I still get an error – user2366475 May 09 '13 at 14:26
  • on this line:this.context = new SP.ClientContext.get_current();SCRIPT5007: Unable to get property 'get_current' of undefined or null reference – user2366475 May 09 '13 at 14:26

4 Answers4

5

You are using ExecuteOrDelayUntilScriptLoaded wrong. You should only pass the function name, it should look like this:

ExecuteOrDelayUntilScriptLoaded(SetWebUserData, "sp.js");

Without the ()

Anders Aune
  • 384
  • 4
  • 8
1

I was able to resolve the issue and have people picker populated with the current user by using code found here: http://vbcity.com/blogs/skullcrusher/archive/2008/11/04/set-sharepoint-peoplepicker-field-mark-2.aspx

This code does not require SP.js

I was never able to get sp.js to load properly, but this solution fixes my problem.

user2366475
  • 31
  • 1
  • 1
  • 3
1

The first parameter of ExecuteOrDelayUntilScriptLoaded has to be a function. This function is called after the requested script file has been loaded.

<SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" 
    Localizable="false" /> 
<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded(SetWebUserData, "SP.js");

function SetWebUserData() {
    var pplPicker = new PeoplePicker();
    // Set the parent tag id of the people the picker.
    pplPicker.SetParentTagId('Main_x0020_Contact');
    pplPicker.SetLoggedInUser();
    };
</script>

With (), you call a function. This means, your error was to pass the result of your function as parameter, not the function itself.

Example for better understanding:

function helloFunction() {
    return 42;
}

var myHelloFunction = helloFunction; // Function is passed
var myHelloFunctionResult = helloFunction(); // Result of your function (42) is passed
Frébo
  • 638
  • 5
  • 12
0

I know that it is a little late, but I think this is the answer you are looking for.

SP.SOD.executeFunc('sp.js', 'SP.ClientContext',function(){
  var pplPicker = new PeoplePicker();
  // Set the parent tag id of the people the picker.
  pplPicker.SetParentTagId('Main_x0020_Contact');
  pplPicker.SetLoggedInUser();
};