0

I would have a list that i am working on and my goal is to load the users name to a text box from active directory when the user click on add new item... Can anyone help me with that?

1 Answer 1

1

You can use the SharePoint Javascript API

    var siteUrl = '/sites/MySiteCollection';

function retrieveAllListProperties() {

var clientContext = new SP.ClientContext(siteUrl);
var oWebsite = clientContext.get_web();
this.collList = oWebsite.get_lists();

clientContext.load(collList);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {

var listInfo = '';

var listEnumerator = collList.getEnumerator();

while (listEnumerator.moveNext()) {
    var oList = listEnumerator.get_current();
    listInfo += 'Title: ' + oList.get_title() + ' Created: ' + oList.get_created().toString() + '\n';
}
alert(listInfo);
}

function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
 }

You can use the SP.ClientContext.CurrentUser property and then set the text to the corresponding textbox with the value you retrieved. Below are the references you will need. The example specified is just demonstrating how to use the SharePoint Javascript OM that OM has access to SharePoint Security Context which in turn gives you the current user information.

<script type="text/ecmascript" src="/_layouts/SP.Core.js" />
<script type="text/ecmascript" src="/_layouts/SP.Debug.js" />
<script type="text/ecmascript" src="/_layouts/SP.Runtime.Debug.js" />
2
  • Awesome thank you very much!
    – TheEisdame
    Oct 9, 2012 at 13:59
  • No problem hope it solves your problem. If it does please click answer buddy :) Oct 9, 2012 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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