I have a created a list for tracking users who have visited the SharePoint Landing Page. This list should contain visited users details like Name, E-Mail and visited time. But the problem here is, The list is getting updated only on my name but not other users. The list is not showing the user names and details who are visiting the site. Please find the code below:

ExecuteOrDelayUntilScriptLoaded(getCurrentUser, "sp.js");

        var currentUser;
        function getCurrentUser(user_name, user_mail) {
            var ctx = new SP.ClientContext.get_current();
            var web = ctx.get_web();
            currentUser = web.get_currentUser();
            ctx.executeQueryAsync(onSuccess, onFailure);
        var user_name = currentUser.get_title();
        var user_mail = currentUser.get_email();

 function onSuccess() {
     var user_name = currentUser.get_title();
     var user_mail = currentUser.get_email();
     console.log(`User Name: ${user_name} and User E-Mail is ${user_mail}`);

function getItems(user_name, user_email) {
  var resturl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('abc')/items";
  var itemTyped = GetItemTypeForListNamed('abc');

    url: resturl,
    type: "POST",
   headers: {
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val() 
      data: JSON.stringify({ '__metadata': { 'type': itemTyped },
        'Title':  user_name,
        'E_x002d_Mail': user_mail
    success: function (data) {
     console.log(`Created Item for ${user_name} and his email is ${user_mail}`); 
    error: function (error) {

function GetItemTypeForListNamed(user_name) {
                return "SP.Data." + user_name.charAt(0).toUpperCase() + user_name.split(" ").join("").slice(1) + "ListItem";
getItems(user_name, user_mail);

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.