Skip to main content
added 62 characters in body; edited tags; edited title; edited tags
Source Link
Ganesh Sanap - MVP
  • 46.4k
  • 22
  • 31
  • 63

How can I join data join 2from two custom lists in sharepoint addinsSharePoint add-ins?

I want join 2 custom lists in addinsadd-ins:

Data of Lists: QuanLyMembers.PhongBanId is ID value of QuanLyPhongBan

QuanLyPhongBan list:

enter image description here  

QuanLyMembers list:

enter image description here This

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 occurthrows an error:

"Value does not fall within the expected range."

How can I join data join 2from two custom lists in sharepoint addinsSharePoint add-ins?

How can join data join 2 custom lists in sharepoint addins?

I want join 2 custom lists in addins:

Data of Lists: QuanLyMembers.PhongBanId is ID value of QuanLyPhongBan

enter image description here  enter image description here 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 occur error:

"Value does not fall within the expected range."

How can join data join 2 custom lists in sharepoint addins?

How can I join data from two custom lists in SharePoint add-ins?

I want join 2 custom lists in add-ins:

Data of Lists: QuanLyMembers.PhongBanId is ID value of QuanLyPhongBan

QuanLyPhongBan list:

enter image description here

QuanLyMembers list:

enter image description here

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?

Source Link
D T
  • 123
  • 5

How can join data join 2 custom lists in sharepoint addins?

I want join 2 custom lists in addins:

Data of Lists: QuanLyMembers.PhongBanId is ID value of QuanLyPhongBan

enter image description here enter image description here 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 occur error:

"Value does not fall within the expected range."

How can join data join 2 custom lists in sharepoint addins?