Created
April 12, 2017 14:22
-
-
Save adamml/46e73c769ef147c270cfc5887c85fa6a to your computer and use it in GitHub Desktop.
SharePoint Online: Wiki Page - Created on; Last modified by; Last Modified on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GetCreatorEditorAndDates() | |
{ | |
var relativePageURL = _spPageContextInfo.serverRequestPath; | |
var siteURL = _spPageContextInfo.webAbsoluteUrl; | |
var profileUrl = "http://mysites.MYCOMPANY.com/Person.aspx?accountname="; <!-- fill in with your own mysites/profile url --> | |
var query = siteURL + "/_api/web/getfilebyserverrelativeurl('/"+ relativePageURL +"')?$select=TimeCreated,Author/Title&$expand=Author/LoginName,TimeLastModified,ModifiedBy/Title,ModifiedBy/LoginName&$expand=ModifiedBy"; | |
var call = $.ajax({ | |
url: query, | |
type: "GET", | |
dataType: "json", | |
headers: { | |
Accept: "application/json;odata=verbose" | |
} | |
}); | |
call.done( (function (data, textStatus, err){ | |
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; | |
var ordinal = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th' ,'th', 'th', 'th', 'st']; | |
var rawModifedDate = new Date(data.d.TimeLastModified); | |
var modifedDate = rawModifedDate.getDate() + ordinal[rawModifedDate.getDate()] + ' ' + months[rawModifedDate.getMonth()] + ' ' +rawModifedDate.getFullYear(); | |
document.getElementById('addedModified').innerHTML = 'Added by ' + data.d.Author.Title + '. Last modified by ' + data.d.ModifiedBy.Title + ' on ' + modifedDate; | |
})); | |
call.fail(function (err,textStatus,errorThrown){ | |
console.log(err); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment