The following example demonstrates how to compare list items between two lists
function getListItems(url,listTitle,success,error)
{
var ctx = new SP.ClientContext(url);
var list = ctx.get_web().get_lists().getByTitle(listTitle);
var items = list.getItems(SP.CamlQuery.createAllItemsQuery());
ctx.load(items);
ctx.executeQueryAsync(function() {
success(items);
},error);
}
function containsAny(items,propertyName,value)
{
var result = items.filter(function(item){ return item.get_item(propertyName) == value });
return (result.length > 0);
}
function compareListItems(settings,success,error)
{
getListItems(settings.Source.Url,settings.Source.Title,
function(sourceItems)
{
getListItems(settings.Target.Url,settings.Target.Title,
function(targetItems)
{
var result = sourceItems.get_data().filter(function(sourceItem){
if(!containsAny(targetItems.get_data(),settings.CompareKey,sourceItem.get_item(settings.CompareKey)))
return sourceItem;
});
success(result);
},
error);
},
error);
}
Usage
Compare list items between two Tasks lists by Title
In your case you could specify RelationShipCol
column
var settings = {
'Source': {
'Url': 'https://contoso.sharepoint.com/sites/news',
'Title': 'Tasks'
},
'Target': {
'Url': 'https://contoso.sharepoint.com/sites/openpositions',
'Title': 'Tasks'
},
'CompareKey': 'Title'
};
compareListItems(settings,
function(data)
{
if(data.length == 0)
console.log('Source and target lists are identical');
else {
console.log('The target lists does not contain the following items:');
data.forEach(function(item){
console.log(item.get_item('Title'));
});
}
},
function(sender,args){
console.log(args.get_message());
});