May 17, 2017 / Kannan / 0 Comments
The following code snippet show how to remove duplicate list items in the JSON result of a SharePoint REST call using JavaScript.
Function Definition:
function RemoveDuplicateItems(items, propertyName) {
var result = [];
if (items.length > 0) {
$.each(items, function (index, item) {
if ($.inArray(item[propertyName], result) == -1) {
result.push(item);
}
});
}
return result;
}
Function Usage:
In the below code, assumption is that, the REST call returns data.d.results and the column for which duplicate items need to be removed is Title
var items = data.d.results;
items = RemoveDuplicateItems(items, 'Title');
May 17, 2017 / Kannan / 0 Comments
Following is a code snippet which show how to pass multiple parameters in JavaScript’s SetTimeout() function.
setTimeout(function () {
CustomFunction(param1, param2, param3, param4, param5);
}, 1000);
May 17, 2017 / Kannan / 0 Comments
Following are some of the JSLink URL Tokens I have come across in SharePoint.
- ~site – reference to the current SharePoint site (or “Web”)
- ~sitecollection – reference to the current SharePoint site collection (or “Site”)
- ~layouts – version specific reference to the web application Layouts folder (so it will automatically swap out /_layouts/14 or /_layouts/15 for you)
- ~sitecollectionlayouts – reference to the layouts folder in the current site collection (e.g. /sites/team/_layouts/15)
- ~sitelayouts – reference to the layouts folder in the current site (e.g. /sites/teams/subsite/_layouts/15)
Few Examples:
~sitecollection/_catalogs/masterpage/
~site/siteassets/
~layouts/reputation.js
Source: https://www.martinhatch.com/2013/08/jslink-and-display-templates-part-1.html