Business

header ads

Javascript How can I return a value for document.write in CEWP with JavaScript

 <script type="text/javascript">


_spBodyOnLoadFunctionNames.push("loadScript");


function loadScript()

{

    ExecuteOrDelayUntilScriptLoaded(findUser, 'sp.js');

}


function findUser() 

cxt = new SP.ClientContext.get_current(); 

web = cxt.get_web(); 

this._currentUser = web.get_currentUser(); 

cxt.load(this._currentUser); 

cxt.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), 

Function.createDelegate(this, this.onFailureMethod)); 

}


function onSuccessMethod(sender, args) 


alert('Welcome ' + this._currentUser.get_title()); 


}


function onFaiureMethod(sender, args) 

alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace()); 

}


</script>

Post a Comment

0 Comments