Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I was trying to display Sharepoint-User name on Pageload in a content editor-webpart using Javascript;
 
Now the following code is working because there is an alert("ppp"); function within the code.
 
If I remove this line It will not displaying the username.
Instead of alert I have tried with timeout function to wait for a while.
But that is also not working. Can you find the reason?. Or Is there any other way to achieve this?
 
Just copy and past the below code to a content-editor webpart for your testing.
 
<script type="text/javascript">
 _spBodyOnLoadFunctionNames.push("CallClientOM()");
        
function CallClientOM() {
 
document.getElementById("DivRequestorName").innerHTML="";
alert("ppp");
            var context = new SP.ClientContext.get_current();
            this.website = context.get_web();
            this.currentUser = website.get_currentUser();
            context.load(currentUser);
            context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
 
        function onQuerySucceeded(sender, args) {
document.getElementById("DivRequestorName").innerHTML =" ";
            document.getElementById("DivRequestorName").innerHTML = currentUser.get_loginName();
        }
 
        function onQueryFailed(sender, args) {        
           
            document.getElementById("DivRequestorName").innerHTML = " ";
        };
 
</script>
 

<div id="DivRequestorName"></div>
Posted 1-Apr-13 2:11am
Edited 1-Apr-13 2:15am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 190
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 Afzaal Ahmad Zeeshan 120
4 DamithSL 115
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 1 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100