Code throwing errors selectively

Forums Classic DFFS Code throwing errors selectively

Viewing 2 reply threads
  • Author
    • #26559

      I have some code in place to set the current user as the value for a people picker field. I have other code that changes fields based on appended text to the url. The people picker code runs fine on the normal newform.aspx but throws errors on the changed urls, despite those changes occurring later in the code than the people picker code. As far as the code is concerned the people picker code should be the same both ways since it’s read first, I’m at a loss for what’s going on (but I’m also new to reading errors in the console so maybe there’s an easy fix?). Below is the relevant code in order it exists in my code

      url field setting code

      function getUrlParameter(name) {
          name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
          var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
          var results = regex.exec(;
          return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));

      people picker code

      $(document).ready(function () {
          // Wait until SP.JS has loaded before calling getWebUserData 
          ExecuteOrDelayUntilScriptLoaded(SetCurrentUsernameToPeoplePicker, "sp.js");
      function SetCurrentUsernameToPeoplePicker(){
      	var ctx = new SP.ClientContext.get_current(); = ctx.get_web();
      	this.currentUser = website.get_currentUser();
      	ctx.executeQueryAsync(Function.createDelegate(this, this.onSucceess), 
      	Function.createDelegate(this, this.onFail));
      function onSucceess(sender, args){
      	var loginName = currentUser.get_loginName();
      	var ppDiv = $("div[id$='ClientPeoplePicker'][class='sp-peoplepicker-topLevel']");	
      	var spPP = SPClientPeoplePicker.SPClientPeoplePickerDict[ppDiv[0].id];
      function onFail(sender, args){
      	alert('request failed ' + args.get_message() + '\n'+ args.get_stackTrace());

      using the url field

      if (getFieldValue('view') === "thing1"){
      //hide, show, readonly, set fields
      else if (getFieldValue('view') === "thing2"){
      //hide, show, readonly, set fields
      else {
      //all the rest of my code with rules and responsiveness that doesn't apply to these limited pre-set views

      f12 console error (can’t copy/paste off my work machine so starting brief, let me know if you need more detail)

      Uncaught ReferenceError: SPClientAutoFill is not defined 
      at Function.SPClientPeoplePicker.AddAutoFillMetaData
      at Function.SPClientPeoplePicker.BuildAutoFillMenuItems
      at Function.SPClientPeoplePicker.UpdateSuggestions
      at Function.SPClientPeoplePicker.UpdateUnresolvedUser
      at Array.ExecutePickerQuery.g
      at SP.ClientRequest
      at Array.<anonymous>

      and for extra clarity, this does NOT happen for url/newform.aspx? but DOES for url/newform.aspx?view=thing1 and url/newform.aspx?view=thing2

    • #26563
      Alexander Bautz

      Not sure why you get this error, but you can do this with less code – try this:

      function dffs_ready(){
          var currUser = spjs.utility.userInfo(_spPageContextInfo.userId);
          var view = GetUrlKeyValue("view");
          // if you want to write view to the field named view you can use the below line
          // setFieldValue("view", view);
              case "thing1":
                  alert("Thing 1");
              case "thing2":
                  alert("Thing 2");
                  alert("No view");

      Replace PeoplePickerFieldInternalName with your field name.


    • #26720

      Side effect of being new to js and getting references from multiple different sources is code not being designed cohesively, I’ll clean up my code using this and let you know if I’m still getting errors. Thanks a ton 🙂

Viewing 2 reply threads
  • You must be logged in to reply to this topic.