Version History Reterival Using JavaScript
Using IFrame Version History:
Showing Version History in Tab
********Ready Function************
$( "#tabs,#tabs2" ).tabs();
//Getting Version History
GetID = getParameterByName('ID'); //alert(GetID);
var ControlEventListurl = L_Menu_BaseUrl + "/_api/web/lists/?$filter=Title eq 'ActionItem'";
$.get(ControlEventListurl, function (data1) {
var resultFin = data1;
var ControlEventListId = "{" + $(resultFin).find('d\\:Id').text() + "}";
if (ControlEventListId == "{}")
ControlEventListId = "{" + $(resultFin).find('Id').text() + "}";
var itemVersionUrl = L_Menu_BaseUrl + "/_layouts/15/Versions.aspx?list=" + ControlEventListId + "&FileName=" + L_Menu_BaseUrl + "/Lists/ActionItem/" + GetID + "_.000&Id=" + GetID + "&IsDlg=1";
// var showurl=L_Menu_BaseUrl + "/_layouts/15/Versions.aspx?list="+ ControlEventListId +"&FileName=" + L_Menu_BaseUrl + "/Lists/LegalSubCase/" + getlistid+ "_.000&Id=" +getlistid;
// $("#showmore").attr("href",showurl);
$("#iframeVersion").attr("src", itemVersionUrl);
$("#iframeVersion ").load(function () {
$("#iframeVersion").contents().find("a[Title='Delete All Versions']").hide();
$("#iframeVersion").contents().find(".ms-propertysheet").each(function () {
$(this).parents("table:first").hide();
});
});
});//End of Version Enabling
*********Under Ready function**********
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
********Setting IFrame************
<iframe id="iframeVersion" height="300px" width="100%"></iframe>*Only past five edits are shown
$( "#tabs,#tabs2" ).tabs();
//Getting Version History
GetID = getParameterByName('ID'); //alert(GetID);
var ControlEventListurl = L_Menu_BaseUrl + "/_api/web/lists/?$filter=Title eq 'ActionItem'";
$.get(ControlEventListurl, function (data1) {
var resultFin = data1;
var ControlEventListId = "{" + $(resultFin).find('d\\:Id').text() + "}";
if (ControlEventListId == "{}")
ControlEventListId = "{" + $(resultFin).find('Id').text() + "}";
var itemVersionUrl = L_Menu_BaseUrl + "/_layouts/15/Versions.aspx?list=" + ControlEventListId + "&FileName=" + L_Menu_BaseUrl + "/Lists/ActionItem/" + GetID + "_.000&Id=" + GetID + "&IsDlg=1";
// var showurl=L_Menu_BaseUrl + "/_layouts/15/Versions.aspx?list="+ ControlEventListId +"&FileName=" + L_Menu_BaseUrl + "/Lists/LegalSubCase/" + getlistid+ "_.000&Id=" +getlistid;
// $("#showmore").attr("href",showurl);
$("#iframeVersion").attr("src", itemVersionUrl);
$("#iframeVersion ").load(function () {
$("#iframeVersion").contents().find("a[Title='Delete All Versions']").hide();
$("#iframeVersion").contents().find(".ms-propertysheet").each(function () {
$(this).parents("table:first").hide();
});
});
});//End of Version Enabling
*********Under Ready function**********
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
********Setting IFrame************
<iframe id="iframeVersion" height="300px" width="100%"></iframe>*Only past five edits are shown
Normal way of displaying Version History
<td><iframe id="iframeVersion" height="300px" width="100%"></iframe>*Only past five edits are shown</td>
<!-- <a id="showmore" style="cursor:pointer">Show more</a>-->
************************** code to put in document.ready()************************
GetID = getParameterByName('ID'); //alert(GetID);
var ControlEventListurl = L_Menu_BaseUrl + "/_api/web/lists/?$filter=Title eq 'Document'";
$.get(ControlEventListurl, function (data1) {
var resultFin = data1;
var ControlEventListId = "{" + $(resultFin).find('d\\:Id').text() + "}";
if (ControlEventListId == "{}")
ControlEventListId = "{" + $(resultFin).find('Id').text() + "}";
var itemVersionUrl = L_Menu_BaseUrl + "/_layouts/15/Versions.aspx?list=" + ControlEventListId + "&FileName=" + L_Menu_BaseUrl + "/Lists/Document/" + GetID + "_.000&Id=" + GetID + "&IsDlg=1";
// var showurl=L_Menu_BaseUrl + "/_layouts/15/Versions.aspx?list="+ ControlEventListId +"&FileName=" + L_Menu_BaseUrl + "/Lists/LegalSubCase/" + getlistid+ "_.000&Id=" +getlistid;
// $("#showmore").attr("href",showurl);
$("#iframeVersion").attr("src", itemVersionUrl);
$("#iframeVersion ").load(function () {
$("#iframeVersion").contents().find("a[Title='Delete All Versions']").hide();
$("#iframeVersion").contents().find(".ms-propertysheet").each(function () {
$(this).parents("table:first").hide();
});
});
});//End of Version Enabling
*************** tz you put below document.ready()**********************
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
http://v-dev-sp-01:8085/sites/ltad/_layouts/15/Versions.aspx?list={b27b36a7-91a7-4114-860b-d91c76fa2e22}&FileName=/sites/ltad/Lists/LegalSubCase/152_.000&Id=152
<!-- <a id="showmore" style="cursor:pointer">Show more</a>-->
************************** code to put in document.ready()************************
GetID = getParameterByName('ID'); //alert(GetID);
var ControlEventListurl = L_Menu_BaseUrl + "/_api/web/lists/?$filter=Title eq 'Document'";
$.get(ControlEventListurl, function (data1) {
var resultFin = data1;
var ControlEventListId = "{" + $(resultFin).find('d\\:Id').text() + "}";
if (ControlEventListId == "{}")
ControlEventListId = "{" + $(resultFin).find('Id').text() + "}";
var itemVersionUrl = L_Menu_BaseUrl + "/_layouts/15/Versions.aspx?list=" + ControlEventListId + "&FileName=" + L_Menu_BaseUrl + "/Lists/Document/" + GetID + "_.000&Id=" + GetID + "&IsDlg=1";
// var showurl=L_Menu_BaseUrl + "/_layouts/15/Versions.aspx?list="+ ControlEventListId +"&FileName=" + L_Menu_BaseUrl + "/Lists/LegalSubCase/" + getlistid+ "_.000&Id=" +getlistid;
// $("#showmore").attr("href",showurl);
$("#iframeVersion").attr("src", itemVersionUrl);
$("#iframeVersion ").load(function () {
$("#iframeVersion").contents().find("a[Title='Delete All Versions']").hide();
$("#iframeVersion").contents().find(".ms-propertysheet").each(function () {
$(this).parents("table:first").hide();
});
});
});//End of Version Enabling
*************** tz you put below document.ready()**********************
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
http://v-dev-sp-01:8085/sites/ltad/_layouts/15/Versions.aspx?list={b27b36a7-91a7-4114-860b-d91c76fa2e22}&FileName=/sites/ltad/Lists/LegalSubCase/152_.000&Id=152
Using SP services to Show Version History
Steps to do:
*First to set a list name correctly in the below JS file.
*Place a JS link on the top(CategoryActionItem.js).
*Place the below code where we required.
<table class="table table-bordered" id="tblversion">
<tr>
<td>Version</td>
<td>Editor</td>
<td>EditDate</td>
</tr>
</table>
*Place a JS link on the top(CategoryActionItem.js).
*Place the below code where we required.
<table class="table table-bordered" id="tblversion">
<tr>
<td>Version</td>
<td>Editor</td>
<td>EditDate</td>
</tr>
</table>
SP Service Code: (Use it as JS File)
var targetList;
//var targetListItem ;
var itemId ;
var i;
$(document).ready(function() {
itemId = GetUrlKeyValue("ID", false, location.href);
//alert(itemId);
VersionShow();
function VersionShow(){
$().SPServices({
debug: true,
operation: "GetVersionCollection",
async: false,
strlistID: "ActionItem",
strlistItemID: itemId ,
strFieldName: "Version",
completefunc: function (xData, Status) {
console.log(xData.responseText);
i=0;
$(xData.responseText).find("Version").each(function(i) {
if(i<5)
{
var date=$(this).attr("Modified").substr(5,2) + "/" + $(this).attr("Modified").substr(8,2) + "/" + $(this).attr("Modified").substr(0,4);
var time=$(this).attr("Modified");
var times= new Date(time);
var validtime = times.toLocaleTimeString();
var data = "<tr><td>" + $(this).attr("Version") + "</td><td>" +$(this).attr("Editor").split("#,#")[1] + "</td><td>" + date +" "+validtime+ "</td></tr>";
$('#tblversion').append(data);
i++;
}
});
}
});
}
});
//var targetListItem ;
var itemId ;
var i;
$(document).ready(function() {
itemId = GetUrlKeyValue("ID", false, location.href);
//alert(itemId);
VersionShow();
function VersionShow(){
$().SPServices({
debug: true,
operation: "GetVersionCollection",
async: false,
strlistID: "ActionItem",
strlistItemID: itemId ,
strFieldName: "Version",
completefunc: function (xData, Status) {
console.log(xData.responseText);
i=0;
$(xData.responseText).find("Version").each(function(i) {
if(i<5)
{
var date=$(this).attr("Modified").substr(5,2) + "/" + $(this).attr("Modified").substr(8,2) + "/" + $(this).attr("Modified").substr(0,4);
var time=$(this).attr("Modified");
var times= new Date(time);
var validtime = times.toLocaleTimeString();
var data = "<tr><td>" + $(this).attr("Version") + "</td><td>" +$(this).attr("Editor").split("#,#")[1] + "</td><td>" + date +" "+validtime+ "</td></tr>";
$('#tblversion').append(data);
i++;
}
});
}
});
}
});
No comments:
Post a Comment