I'm happy to say this is my 200th blog in C-SharpCorner.
Normally, in a list, where we havea Person/Group column (say Employee), when we use REST API to get this column value, we get User ID instead of an actual value, which we see in list column.
The reason behind this is Person/Group column is actually a lookup field internally.
Steps
- Open your Notepad.
- Copy the code given below and paste it.
- Name it as like spvalidation.js.
- Add Content Editor Webpart in your page.
- Add saved .js file into your Webpart properties.
Source code
- <script>
- $(document).ready(function () {
-
- GetUserLogin();
-
- });
-
- var userid = _spPageContextInfo.userId;
-
- function GetUserLogin() {
- var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
-
- var requestHeaders = { "accept" : "application/json;odata=verbose" };
-
- $.ajax({
- url : requestUri,
- contentType : "application/json;odata=verbose",
- headers : requestHeaders,
- success : QuerySuccess,
- error : QueryError
- });
- }
-
- function QuerySuccess(data, request){
-
- var loginName = data.d.LoginName.split('|')[1];
- $("div[title='Enter the People picker column Name']").val(loginName);
- }
-
- function QueryError(error) {
- alert(error);
- }
- </script>
Was my blog helpful? If yes, please let me know and if not, please explain what was confusing or missing.
I’ll use your feedback to double-check the facts, add info, and update this blog.
Thanks to all SharePoint readers.