none
how to specify default value for people or group field in sharepoint with current user RRS feed

  • Question

  • Hi all,

    Can anyone tell me how can we specify the default value for people or group field with the current user id in sharepoint

    Saturday, December 18, 2010 11:50 AM

Answers

  • Hi,

    Do you want to fill on list pages? (ie newform.aspx, editform.aspx etc) If yes then a small jaavscript can help you.

    1. Add a CEWB on your page

    2. Try to use below java script

    <script type="text/javascript">
    _spBodyOnLoadFunctionNames.push("fillDefaultValues");
     
    function fillDefaultValues() {
      var qs = location.search.substring(1, location.search.length);
      var args = qs.split("&");
      var vals = new Object(getUserDisplayName());
      
      var assignedToInput = getTagFromIdentifierAndTitle("div", "", "People Picker");
      assignedToInput.innerHTML = vals;
      for (var i=0; i < args.length; i++) {
        var nameVal = args[i].split("=");
        var temp = unescape(nameVal[1]).split('+');
        nameVal[1] = temp.join(' ');
        vals[nameVal[0]] = nameVal[1];
      }  
    }
     
    function getTagFromIdentifierAndTitle(tagName, identifier, title) {
      var len = identifier.length;
      var tags = document.getElementsByTagName(tagName);
      for (var i=0; i < tags.length; i++) {
        var tempString = tags[i].id;
        if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
          return tags[i];
        }
      }
      return null;
    }
    function getUserDisplayName() {
     var tags = document.getElementsByTagName('a');
     for (var i=0; i < tags.length; i++) {
      if(tags[i].innerText.substr(0,7) == 'Welcome') {
       return tags[i].innerText.substr(8,tags[i].innerText.length);
      }
     }
    }
    </script>
    For more ref:

    Hope this will help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    • Marked as answer by Leoyi Sun Monday, December 27, 2010 11:53 AM
    Monday, December 20, 2010 5:28 AM
    Moderator

All replies

  • Are u talking about populating default user information (including his user id / full name) in a list ? If Yes, then one of the ways i'd suggest is by following the below blog post by Laura Rogers. It works perfectly, the only caveat is your MOSS farm needs to be enabled with enterprise version and NOT standard.

    http://www.sharepoint911.com/blogs/laura/Lists/Posts/Post.aspx?List=676af157%2D7d96%2D4e15%2Da987%2D54b8a3e4d948&ID=73

     

    Sunday, December 19, 2010 11:15 AM
  • Hi,

    Do you want to fill on list pages? (ie newform.aspx, editform.aspx etc) If yes then a small jaavscript can help you.

    1. Add a CEWB on your page

    2. Try to use below java script

    <script type="text/javascript">
    _spBodyOnLoadFunctionNames.push("fillDefaultValues");
     
    function fillDefaultValues() {
      var qs = location.search.substring(1, location.search.length);
      var args = qs.split("&");
      var vals = new Object(getUserDisplayName());
      
      var assignedToInput = getTagFromIdentifierAndTitle("div", "", "People Picker");
      assignedToInput.innerHTML = vals;
      for (var i=0; i < args.length; i++) {
        var nameVal = args[i].split("=");
        var temp = unescape(nameVal[1]).split('+');
        nameVal[1] = temp.join(' ');
        vals[nameVal[0]] = nameVal[1];
      }  
    }
     
    function getTagFromIdentifierAndTitle(tagName, identifier, title) {
      var len = identifier.length;
      var tags = document.getElementsByTagName(tagName);
      for (var i=0; i < tags.length; i++) {
        var tempString = tags[i].id;
        if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
          return tags[i];
        }
      }
      return null;
    }
    function getUserDisplayName() {
     var tags = document.getElementsByTagName('a');
     for (var i=0; i < tags.length; i++) {
      if(tags[i].innerText.substr(0,7) == 'Welcome') {
       return tags[i].innerText.substr(8,tags[i].innerText.length);
      }
     }
    }
    </script>
    For more ref:

    Hope this will help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    • Marked as answer by Leoyi Sun Monday, December 27, 2010 11:53 AM
    Monday, December 20, 2010 5:28 AM
    Moderator
  • View this add-on(SharePoint Default Value Add-On), which inject a "default value" section into "Create Column" dialog.

    Set "Current User" (User who is adding item) as default value.


    We deliver powerful and smart SharePoint Add-Ons and web parts for your SharePoint 2010
    SharePoint Employee Directory|Password Change & Expiration|Cross-Site Lookup Column|More

    Saturday, September 21, 2013 1:32 PM
  • Sorry I am new in SharePoint.

    I really appreciate if you can explain step by step procedure

    1. Add a CEWB on your page1? ( I have SharePoint List where I want to have default user column)

    Thank you


    simam

    Tuesday, February 4, 2014 12:28 AM
  • thank you for the script, but, how it could be if we want to use another user?, thank you
    Tuesday, September 20, 2016 8:08 PM
  • I'm still waiting for an "Out of the Box" way to do this so if anyone else is in the same boat maybe we can vote it in on Uservoice.

    https://sharepoint.uservoice.com/forums/329214-sites-and-collaboration/suggestions/16029844-automate-populate-person-field-with-me-value 

    Whilst there seems to be a number of ways of achieving this through custom approaches it would appear like a fairly easy function for Microsoft to just add to the product.


    • Edited by DaveHDub Wednesday, August 16, 2017 1:13 PM
    Wednesday, August 16, 2017 1:09 PM
  • Hi! Does this work in Sharepoint Online? I added the CEWP but does nothing. Is there a particular setting for the column besides being a People/Group selection? Thanks!
    • Edited by IQuinones Thursday, September 14, 2017 2:32 PM
    Thursday, September 14, 2017 2:32 PM