Show modified by author and date in all pages in O365 SharePoint site using below script,
$(document).ready(function() {
GetEditorAndDate();
}); // end document-ready
function GetEditorAndDate()
{
var relativePageURL = _spPageContextInfo.serverRequestPath;
var siteURL = _spPageContextInfo.webAbsoluteUrl;
var profileUrl = "https://myorg.sharepoint.com/sites/devsite/";
var query = siteURL + "/_api/web/getfilebyserverrelativeurl('/"+ relativePageURL +"')?$select=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){
rawModifedBy = data.d.ModifiedBy.Title
prettiedModifiedBy = rawModifedBy.split(', ')[1]+' '+ rawModifedBy.split(', ')[0]
rawModifiedId=data.d.ModifiedBy.LoginName; //<d:LoginName>i:0#.w|klasj\kpereyra</d:LoginName>
var modifiedId= rawModifiedId.replace('i:0#.w|', '') <!-- needed only if your data returns in the format <d:LoginName>i:0#.w|DOMAIN\USERNAME</d:LoginName> -->
var rawModifedDate = new Date(data.d.TimeLastModified);
console.log("Page modified data"+data.d);
var mm = rawModifedDate.getMonth()+1;
var modifedDate= rawModifedDate.toLocaleDateString()+" "+rawModifedDate.toLocaleTimeString();
var aboveFooter = '<div id="freshIndicator" style="width: 500px;margin-left: auto;margin-right: auto;">This page was last modified by ' + prettiedModifiedBy +' on '+ modifedDate +'</div>'
$(".footer").append(aboveFooter); <!-- assumes a footer with the id "footer". If you don't have one, put it after the end script tag. -->
}));
call.fail(function (err,textStatus,errorThrown){
console.log(err);
});
}
Hope this helps someone!
$(document).ready(function() {
GetEditorAndDate();
}); // end document-ready
function GetEditorAndDate()
{
var relativePageURL = _spPageContextInfo.serverRequestPath;
var siteURL = _spPageContextInfo.webAbsoluteUrl;
var profileUrl = "https://myorg.sharepoint.com/sites/devsite/";
var query = siteURL + "/_api/web/getfilebyserverrelativeurl('/"+ relativePageURL +"')?$select=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){
rawModifedBy = data.d.ModifiedBy.Title
prettiedModifiedBy = rawModifedBy.split(', ')[1]+' '+ rawModifedBy.split(', ')[0]
rawModifiedId=data.d.ModifiedBy.LoginName; //<d:LoginName>i:0#.w|klasj\kpereyra</d:LoginName>
var modifiedId= rawModifiedId.replace('i:0#.w|', '') <!-- needed only if your data returns in the format <d:LoginName>i:0#.w|DOMAIN\USERNAME</d:LoginName> -->
var rawModifedDate = new Date(data.d.TimeLastModified);
console.log("Page modified data"+data.d);
var mm = rawModifedDate.getMonth()+1;
var modifedDate= rawModifedDate.toLocaleDateString()+" "+rawModifedDate.toLocaleTimeString();
var aboveFooter = '<div id="freshIndicator" style="width: 500px;margin-left: auto;margin-right: auto;">This page was last modified by ' + prettiedModifiedBy +' on '+ modifedDate +'</div>'
$(".footer").append(aboveFooter); <!-- assumes a footer with the id "footer". If you don't have one, put it after the end script tag. -->
}));
call.fail(function (err,textStatus,errorThrown){
console.log(err);
});
}
Hope this helps someone!
Comments
Post a Comment