0

I am trying to create a newform that has the user name autopopulate on opening the form. I have tried using SPServices.SPGetCurrentUser however I keep getting an error saying unidentified or Null. I am using sharepoint foundation 2013, and I cannot use Visual studio, only Designer with jquery and javascript. Any help would be appreciated.

2

Make sure jQuery is loaded as its working

<script type="text/javascript">
  var userid= _spPageContextInfo.userId;
  var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
  var requestHeaders = { "accept" : "application/json;odata=verbose" };
  $.ajax({
    url : requestUri,
    contentType : "application/json;odata=verbose",
    headers : requestHeaders,
    success : onSuccess,
    error : onError
  });

  function onSuccess(data, request){
    var loginName = data.d.Title;
    $('#textboxid').val(loginName);
  }

  function onError(error) {
    alert("error");
  }
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.