Tuesday, October 7, 2014
Thursday, August 21, 2014
Get Item count in array using jquery
GetItemCountInArray: function (myArr, item) {
num = 0;
for (i = 0; i <= myArr.length; i++) {
if (myArr[i] == item)
num++;
}
return num;
}
num = 0;
for (i = 0; i <= myArr.length; i++) {
if (myArr[i] == item)
num++;
}
return num;
}
Wednesday, August 20, 2014
get unique values from array jquery
GetUnique: function (inputArray) {
var outputArray = [];
for (var i = 0; i < inputArray.length; i++) {
if ((jQuery.inArray(inputArray[i], outputArray)) == -1) {
outputArray.push(inputArray[i]);
}
}
return outputArray;
}
var outputArray = [];
for (var i = 0; i < inputArray.length; i++) {
if ((jQuery.inArray(inputArray[i], outputArray)) == -1) {
outputArray.push(inputArray[i]);
}
}
return outputArray;
}
Delete Item From Custom list By caml query sharepoint 2013
deleteDataFromListByQuery: function (customListName, query, columns) {
var scriptbase = hostUrl + "/_layouts/15/";
$.getScript(scriptbase + 'SP.Runtime.js',
function () {
$.getScript(scriptbase + 'SP.js',
function () {
$.getScript(scriptbase + 'SP.RequestExecutor.js', deleteItem);
});
});
function deleteItem() {
var context;
var factory;
var appContextSite;
var mylist;
context = new SP.ClientContext(appweburl);
factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, hostUrl);
this.web = appContextSite.get_web();
mylist = this.web.get_lists().getByTitle(customListName);//Custom List Name
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(query);
var collListItem = mylist.getItems(camlQuery);
context.load(mylist);
context.load(collListItem);
context.executeQueryAsync(
function () {
var listItemEnumerator = collListItem.getEnumerator();
var counter = 0;
var itemArr = new Array();
var id;
while (listItemEnumerator.moveNext()) {
var listItem = listItemEnumerator.get_current();
//itemArr[counter] = listItem.get_item("ID");
//counter++;
id = listItem.get_item('ID');
var spItem = mylist.getItemById(id);
spItem.deleteObject();
}
// for (var id in itemArr) {
// var spItem = mylist.getItemById(itemArr[id]);
// spItem.deleteObject();
// }
context.executeQueryAsync(
function () {
alert('success');
},
function () {
error();
});
},
function () {
error();
});
}
}
var scriptbase = hostUrl + "/_layouts/15/";
$.getScript(scriptbase + 'SP.Runtime.js',
function () {
$.getScript(scriptbase + 'SP.js',
function () {
$.getScript(scriptbase + 'SP.RequestExecutor.js', deleteItem);
});
});
function deleteItem() {
var context;
var factory;
var appContextSite;
var mylist;
context = new SP.ClientContext(appweburl);
factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, hostUrl);
this.web = appContextSite.get_web();
mylist = this.web.get_lists().getByTitle(customListName);//Custom List Name
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(query);
var collListItem = mylist.getItems(camlQuery);
context.load(mylist);
context.load(collListItem);
context.executeQueryAsync(
function () {
var listItemEnumerator = collListItem.getEnumerator();
var counter = 0;
var itemArr = new Array();
var id;
while (listItemEnumerator.moveNext()) {
var listItem = listItemEnumerator.get_current();
//itemArr[counter] = listItem.get_item("ID");
//counter++;
id = listItem.get_item('ID');
var spItem = mylist.getItemById(id);
spItem.deleteObject();
}
// for (var id in itemArr) {
// var spItem = mylist.getItemById(itemArr[id]);
// spItem.deleteObject();
// }
context.executeQueryAsync(
function () {
alert('success');
},
function () {
error();
});
},
function () {
error();
});
}
}
Delete Item from custom list in sharepoint 2013 using Caml query and JSOM
1) function deleteItem(id) {
//REST.Common.deleteDataFromParentList(customlist.TravelRequestlist, id);
var department = 52;
var customListName = 'TMS_AirBooking';//Custom List Name
var query = '<View><Query><Where><Eq><FieldRef Name=\'Travel_Req_No\'/>' +
'<Value Type=\'Number\'>' + department + '</Value></Eq></Where></Query><RowLimit>10</RowLimit></View>';
var columns = ['Travel_Req_No'];
deleteDataFromChildList(customListName, query, columns);
// alert(id + ',' + 'TravelRequests');
}
2) deleteDataFromChildList: function (customListName, query, columns) {
var scriptbase = hostUrl + "/_layouts/15/";
$.getScript(scriptbase + 'SP.Runtime.js',
function () {
$.getScript(scriptbase + 'SP.js',
function () {
$.getScript(scriptbase + 'SP.RequestExecutor.js', deleteItem);
});
});
function deleteItem() {
var context;
var factory;
var appContextSite;
var mylist;
context = new SP.ClientContext(appweburl);
factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, hostUrl);
this.web = appContextSite.get_web();
mylist = this.web.get_lists().getByTitle(customListName);//Custom List Name
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(query);
var collListItem = mylist.getItems(camlQuery);
context.load(mylist);
context.load(collListItem);
context.executeQueryAsync(
function () {
var listItemEnumerator = collListItem.getEnumerator();
var counter = 0;
var itemArr = new Array();
while (listItemEnumerator.moveNext()) {
var listItem = listItemEnumerator.get_current();
itemArr[counter] = listItem.get_item("ID");
counter++;
}
for (var id in itemArr) {
var spItem = mylist.getItemById(itemArr[id]);
spItem.deleteObject();
}
context.executeQueryAsync(
function () {
alert('success');
},
function () {
error();
});
},
function () {
error();
});
}
}
//REST.Common.deleteDataFromParentList(customlist.TravelRequestlist, id);
var department = 52;
var customListName = 'TMS_AirBooking';//Custom List Name
var query = '<View><Query><Where><Eq><FieldRef Name=\'Travel_Req_No\'/>' +
'<Value Type=\'Number\'>' + department + '</Value></Eq></Where></Query><RowLimit>10</RowLimit></View>';
var columns = ['Travel_Req_No'];
deleteDataFromChildList(customListName, query, columns);
// alert(id + ',' + 'TravelRequests');
}
2) deleteDataFromChildList: function (customListName, query, columns) {
var scriptbase = hostUrl + "/_layouts/15/";
$.getScript(scriptbase + 'SP.Runtime.js',
function () {
$.getScript(scriptbase + 'SP.js',
function () {
$.getScript(scriptbase + 'SP.RequestExecutor.js', deleteItem);
});
});
function deleteItem() {
var context;
var factory;
var appContextSite;
var mylist;
context = new SP.ClientContext(appweburl);
factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, hostUrl);
this.web = appContextSite.get_web();
mylist = this.web.get_lists().getByTitle(customListName);//Custom List Name
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(query);
var collListItem = mylist.getItems(camlQuery);
context.load(mylist);
context.load(collListItem);
context.executeQueryAsync(
function () {
var listItemEnumerator = collListItem.getEnumerator();
var counter = 0;
var itemArr = new Array();
while (listItemEnumerator.moveNext()) {
var listItem = listItemEnumerator.get_current();
itemArr[counter] = listItem.get_item("ID");
counter++;
}
for (var id in itemArr) {
var spItem = mylist.getItemById(itemArr[id]);
spItem.deleteObject();
}
context.executeQueryAsync(
function () {
alert('success');
},
function () {
error();
});
},
function () {
error();
});
}
}
Wednesday, August 13, 2014
Popup in sharepoint 2013 with ModalDialog
openDialog: function (id) {
SP.UI.ModalDialog.showModalDialog({
url: "Edit.aspx?ID=" + id + "&SPHostUrl=" + hostUrl + "&SPAppWebUrl=" + appweburl + "",
title: "Edit",
allowMaximize: false,
showClose: true,
width: 400,
height: 200
});
}
SP.UI.ModalDialog.showModalDialog({
url: "Edit.aspx?ID=" + id + "&SPHostUrl=" + hostUrl + "&SPAppWebUrl=" + appweburl + "",
title: "Edit",
allowMaximize: false,
showClose: true,
width: 400,
height: 200
});
}
Subscribe to:
Posts (Atom)