Title: Get Login ID, Name and display that data in Textbox.
Description:
We have requirement that need
to fill the form. To fill the form User ID and User name is a Log in User
information. To full fill that requirement we will get the User Id and User
name and bind information to the appropriate text boxes.
Steps:
Design Form:
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- var currentUser;
- if (SP.ClientContext != null) {
- SP.SOD.executeOrDelayUntilScriptLoaded(getCurrentUser, 'SP.js');
- } else {
- SP.SOD.executeFunc('sp.js', null, getCurrentUser);
- }
- });
- function getCurrentUser() {
- context = new SP.ClientContext.get_current();
- web = context.get_web();
- currentUser = web.get_currentUser();
- context.load(currentUser);
- context.executeQueryAsync(onSuccess, onRequestFail);
- }
- function onSuccess(sender, args) {
- $('#currentUserID').val(currentUser.get_id())
- $('#currentUserName').val(currentUser.get_title())
- }
- function onRequestFail(sender, args) {
- alert('request failed' + args.get_message());
- }
- </script>
- Customer ID <input type="text" id="currentUserID" /> </br>
- Customer Name <input type="text" id="currentUserName" /> </br>
- Location <input type="text" id="currentUserID" /> </br>
- Address <input type="text" id="currentUserName" />