Skip to main content

How to delete duplicates from SharePoint list using JSOM

How to delete duplicates from SharePoint list using JSOM, Credit: Thulasi Pasam Reference: https://community.nintex.com/thread/8516

Note:
  1. Make sure the reference file paths
  2. Make sure the column to test duplicate on CAML query
  3. Update your SharePoint list name

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=5, IE=8, IE=9, IE=10" >

</head>
<body>
<div Id="myDiv" style= "width: 75%;">
<table id="tblHeading"  width = "100%" align = "left">
<tr style ="width:100%;">
<td><input type= "button" onclick="Delete()" align = "Center" alt="Delete Duplicates" value="Delete"></td>
</tr>
</table>


</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://sharepoint.jtafla.com/sites/ROI/Scripts/spjs-utility.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.2/jquery.SPServices-0.7.2.min.js" ></script>

<script>
var ListA = new Array();
var ListB = new Array();
var strList= 'Your List Name';

$(document).ready (function() {
GetAllListA();

});

function GetAllListA(){
var vblMembers ='';
var strQuery= "<Query> <OrderBy>  <FieldRef Name='User_Email_Address' Ascending='TRUE' />       </OrderBy>      </Query>";

$().SPServices({
operation: "GetListItems",
async: false,
listName: strList,
CAMLQuery: strQuery,
completefunc: function (xData, Status) {
if(Status == 'success')
{
$(xData.responseXML).SPFilterNode("z:row").each(function(){

ListA.push($(this).attr("ows_User_Email_Address"));
});
}
}
    });

}

function GetAllListB(){
var vblMembers ='';
var strQuery= "<Query> <OrderBy>  <FieldRef Name='User_Email_Address' Ascending='TRUE' />       </OrderBy>      </Query>";
ListB = [];
$().SPServices({
operation: "GetListItems",
async: false,
listName: strList,
CAMLQuery: strQuery,
completefunc: function (xData, Status) {
if(Status == 'success')
{
$(xData.responseXML).SPFilterNode("z:row").each(function(){

ListB.push($(this).attr("ows_User_Email_Address"));
});
}
}
    });

}

function Delete(){
GetAllListA();
GetAllListB();

for (var i=0; i<ListA.length; i++) {
var count = 0;

for (var j=0; j<ListB.length; j++)
{
if(ListA[i] == ListB[j])
{
count = count+1;
if (count > 1)
{
DeleteDuplicate(ListA[i]);
GetAllListB();
count = 0;
break;
}
}
}
if (count > 1)
{
count = 0;
break;
}

}
alert('All duplicates are removed!');
}

function DeleteDuplicate(tempName){
var delId = GetIdByName(tempName);
alert(delId != "undefined")
{
$().SPServices({
operation:"UpdateListItems",
async: false,
batchCmd: "Delete",
listName: strList,
ID: delId,
completefunc:function(xData, Status)
{
   //alert("Item Deleted");
}
});
}
}

function GetIdByName(tempName){
var vblMembers ='';
var strQuery = "<Query><Where><Eq><FieldRef Name='User_Email_Address'/><Value Type='text'>"+tempName+"</Value></Eq></Where></Query>";
    var tempid = new Array();
$().SPServices({
operation: "GetListItems",
async: false,
listName: strList,
CAMLQuery: strQuery,
completefunc: function (xData, Status) {
if(Status == 'success')
{
$(xData.responseXML).SPFilterNode("z:row").each(function(){

tempid.push($(this).attr("ows_ID"));
});
}
}
    });
return tempid[0];
}
</script>
</html>

Comments

  1. Post writing is also a fun, if you know after that you can write if not it is complex to write.

    ReplyDelete
  2. Thanks in favor of sharing such a nice thinking, paragraph is nice, thats why i have read it fully

    ReplyDelete

Post a Comment

Popular posts from this blog

Permission audit report for site and all sub sites using PowerShell

Use below script to get Permission audit report for site and all sub sites using PowerShell, Add-PSSnapin "Microsoft.SharePoint.PowerShell" $URL="https://intranet.contoso.com/sales/mysite/"      $site = Get-SPSite $URL      #Write the Header to "Tab Separated Text File"         "Site Name`t  URL `t Group Name `t User Account `t User Name `t E-Mail" | out-file "E:\Ulhas\UsersandGroupsRpt.txt"          #Iterate through all Webs       foreach ($web in $site.AllWebs)       {         #Write the Header to "Tab Separated Text File"         "$($web.title) `t $($web.URL) `t  `t  `t `t " | out-file "E:\Ulhas\UsersandGroupsRpt.txt" -append          #Get all Groups and Iterate through            foreach ($group in $Web.groups)         ...

How Internet Bots Works?

What is bot? An internet robot or simply a bot is a software application that runs automated scripts on the web. How it works? Typically bots perform tasks that are simple and structurally repetitive at a much higher rate than what is possible for human being. So one single bot can handle queries(in whatever format like voice, chat OR Email) of hundreds of customers at the same time. Companies don't want their bots to sound too mechanical or business-like so we need to do a lot of cultural adaption in bots. Machine Learning and Artificial Intellingence (AI) form the underlying base of bots. For businesses to start their bots programme, they should collect a lot of customer related data. This fragmented data is used to populate the knowledge bank servers. Bots which understand behavior pattern will be able to pick "odd" transaction requests like humans do. Most of the Social Media platforms are using bots for most common activities. Below is the pictorial exp...