Share via


Get Current User Display Name and Field Read Only

Question

Wednesday, January 24, 2018 2:29 PM

Hi all,

I'm created get current user using javascript, but  i want field display user name only and make the field as read only.

Anyone know?

Thanks :)

I'm Beginner.

All replies (6)

Wednesday, January 24, 2018 2:59 PM

Hi

Please refer below link, hope it can help:

http://www.sharepointdiary.com/2013/07/how-to-make-sharepoint-list-column-form-field-read-only.html


Thursday, January 25, 2018 5:42 AM

Hi Tina Yi,

Can i use web part?


Thursday, January 25, 2018 6:08 AM

I don't understand what's your field?

You can disable the field and make it read only  by javascript or jquery.

Also you can develop a webpart, but it's complex.


Thursday, January 25, 2018 6:27 AM

Oh i see,

Any suggestion  if i use JS ?

Why if i using webpart it's complex?


Thursday, January 25, 2018 10:10 AM

Hi,

You can enter the scripts in Content Editor web part or Script Editor web part on the page.

For SharePoint Online, we can use _spPageContextInfo object to get the current user name. It provides the userId and userLoginName properties.

For example:

<script type="text/javascript">

var loginName = _spPageContextInfo.userLoginName;

alert(loginName);

</script>

Using JavaScript to set the field value in the form. Then, set the field to ready only.

A demo: set a field value via JavaScript

<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function(){

$("input[Title='<column>']").val(loginName);

});

</script>

Best regards,

Linda Zhang

Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact [email protected].


Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.


Friday, January 26, 2018 6:49 AM

You can do it by JQuery.

$("input[title='Title']").attr('disabled',"true");

//[title='Title'] - Title is your column name

Please remember to mark the replies as answers if they helped.

Linyu - SharePoint Engineer

Blog: http://blog.csdn.net/linyustar

GitHub: https://github.com/linyus

QQ Group: 72637444