I want join 2 custom lists in add-ins:
Data of Lists: QuanLyMembers.PhongBanId
is ID
value of QuanLyPhongBan
QuanLyPhongBan list:
QuanLyMembers list:
This is my code:
function getListMem() {
//var hostWebContext = new SP.AppContextSite(clientContext, hostWebURL);
var listStatus = clientContext.get_web().get_lists().getByTitle('QuanLyMembers');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><ViewFields><FieldRef Name='Id'/><FieldRef Name='Title'/>" +
"<FieldRef Name='EmailContact'/><FieldRef Name='PhongBanName'/></ViewFields>" +
"<Joins><Join Type ='INNER' ListAlias ='QuanLyPhongBan'><Eq><FieldRef Name='PhongBanId' RefType='Id' /><FieldRef List='QuanLyPhongBan' Name='ID' /></Eq>" +
"<ProjectedFields><Field Name='PhongBanName' Type='Lookup' List='QuanLyPhongBan' ShowField='Title'/> </ProjectedFields></Join>" +
"</Joins></View>");
var Items = listStatus.getItems(camlQuery);
clientContext.load(Items, 'Include(Title,EmailContact,Id,PhongBanName)');
clientContext.executeQueryAsync(Function.createDelegate(this, function () {
var oEnumerator = Items.getEnumerator();
while (oEnumerator.moveNext()) {
var id = oEnumerator.get_current().get_id();
var title = oEnumerator.get_current().get_item('Title');
var PhongBanName = oEnumerator.get_current().get_item('PhongBanName ');
var EmailContact = oEnumerator.get_current().get_item('EmailContact');
}
}), Function.createDelegate(this, function (sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}));
}
But it throws an error:
"Value does not fall within the expected range."
How can I join data from two custom lists in SharePoint add-ins?