Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 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" />
share|improve this answer
    
Awesome thank you very much! –  TheEisdame Oct 9 '12 at 13:59
    
No problem hope it solves your problem. If it does please click answer buddy :) –  Joseph D Surgeon Oct 9 '12 at 14:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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