Skip to content

Instantly share code, notes, and snippets.

@premchandpl
premchandpl / CompleteFunction.js
Last active August 29, 2015 14:02
Complete Code Snippet
that.getData = function (listName, xmlQuery, contentType, onGetSuccess) {
var objClientCtx = new SP.ClientContext.get_current();
if (objClientCtx) {
var oWeb = objClientCtx.get_web();
var oList = oWeb.get_lists().getByTitle(listName);
var query = new SP.CamlQuery();
query.set_viewXml(xmlQuery);
var objlistItems = oList.getItems(query);
objClientCtx.load(objlistItems);
objClientCtx.executeQueryAsync(function (sender, args) {
that.GetSharePointListData = function (spListName, camlQuery) {
SP.SOD.executeFunc("sp.js", 'SP.ClientContext', function () {
that.getData(spListName, camlQuery);
});
}
@premchandpl
premchandpl / SharePointcontext.js
Created June 13, 2014 21:21
SharePoint context
var objClientCtx = new SP.ClientContext.get_current();
@premchandpl
premchandpl / GetListItems.js
Created June 13, 2014 21:22
Get List Items
var oWeb = objClientCtx.get_web();
var oList = oWeb.get_lists().getByTitle(listName);
var query = new SP.CamlQuery();
query.set_viewXml(xmlQuery);
var objlistItems = oList.getItems(query);
objClientCtx.load(objlistItems);
@premchandpl
premchandpl / GetIndividualItem.js
Last active August 29, 2015 14:02
Get Individual Item
objClientCtx.executeQueryAsync(function (sender, args) {
that.DataSet = [];
var objlistEnumerator = objlistItems.getEnumerator();
while (objlistEnumerator.moveNext()) {
var objListItem = objlistEnumerator.get_current();
var id = objListItem.get_item('ID');
var filePath = 'Path to current list/ListName/'+id+'_.000'
var web = objClientCtx.get_web();
var listItemInfo = web.getFileByServerRelativeUrl(filePath)
@premchandpl
premchandpl / GetListItemVersion
Last active August 29, 2015 14:02
Get List Item Versions
objClientCtx.executeQueryAsync(
function (sender, args) {
var fileVersions = listItemInfo.get_versions();
objClientCtx.load(fileVersions);
@premchandpl
premchandpl / GetAllVersions.js
Last active August 29, 2015 14:02
Get all versions
var objlistVersionEnumerator = fileVersions.getEnumerator();
while (objlistVersionEnumerator.moveNext()) {
var objCurrentListItemVersion = objlistVersionEnumerator.get_current();
conso9le.log(objCurrentListItemVersion.get_url());
@premchandpl
premchandpl / VersionHistoryUrl.js
Created June 13, 2014 22:10
version history url
_vti_history/512/Lists/List Name/265_.000
@premchandpl
premchandpl / GetVersiondata.js
Created June 13, 2014 22:28
Get version data
var $div = $('<div>');
$div.load('Site collection path/Lists/ListName/DispForm.aspx?ID=265&VersionNo=1024 table.ms-formtable', function(){
var table = $(this).find('table.ms-formtable');
var tr = $(table).find('tr');
$(tr).each(function(){
var row = $(this);
var columnName = $.trim(row.find('td:eq(0)').text());
var columnValue = $.trim(row.find('td:eq(1)').text());
console.log(columnName);
console.log(columnValue);
that.GetSharePointListData = function (listName, camlQuery, onGetSuccess) {
SP.SOD.executeFunc("sp.js", 'SP.ClientContext', function () {
that._getData(listName, camlQuery, onGetSuccess);
});
}