Skip to content

Instantly share code, notes, and snippets.

@adamml
Created April 12, 2017 14:22
Show Gist options
  • Save adamml/46e73c769ef147c270cfc5887c85fa6a to your computer and use it in GitHub Desktop.
Save adamml/46e73c769ef147c270cfc5887c85fa6a to your computer and use it in GitHub Desktop.
SharePoint Online: Wiki Page - Created on; Last modified by; Last Modified on
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