Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6786
  • Last Modified:

Retrieve data from two SharePoint list using jquery

Hi All,
   I'm working on a page to display the data from two sharepoint lists.

SharePoint List 1: ID, Name, Position, Project
SharePoint List 2: ReferenceID, Worklocation
    ** ReferenceID = ID in SharePoint List 1

I would like to display the data in a table when the Project = A, there might have few items in the SharePoint 1

Result Table:
Project Name: Project A
ID, Name, Position, Work Location
2, Name2, Position2, Work Location2
3 Name 3 Positoin3, Worklocation3

I can't figure out how to query data to display the info in sharepoint 1 & sharepoint list 2 in jquery. If anyone can help that would be great.

Thanks.
sb
0
seebeelim
Asked:
seebeelim
  • 2
  • 2
2 Solutions
 
Nuno RogadoCommented:
Hi sb,

Which version of SharePoint are you using?
SharePoint List 2, field Reference ID is a lookup field configured to SharePoint List 1?

Best Regards,
Nuno Rogado
0
 
Jayaraja JayaramanSharepoint Architect ConsultantCommented:
Create a linked datasource via SPD and get the join result set using merge content. from there on you can create a dataview webpart and have this connected lists as the datasource.

Tutorial here
https://www.nothingbutsharepoint.com/sites/eusp/Pages/How-to-Link-Two-Lists-and-Create-a-Combined-View-in-SharePoint-2010.aspx
0
 
seebeelimAuthor Commented:
Hi Nuno, Jayaraya
  I'm using Sharepoint 2013 in office 365. As using lookup will impact the current structure i have. In SPD 2013, is there any way to do data source merging, i can't find it anywhere.
   I managed to use camlquery and spservices (GetListItem) in between to get the information from SharePoint list 2

Function GetSharePointList1() {
context = SP.ClientContext.get_current();
    oList = context.get_web().get_lists().getByTitle('SharePoint List 2');
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml(query);
    items = oList.getItems(camlQuery);
    context.load(items);
   
    context.executeQueryAsync(
        Function.createDelegate(this, onSuccessSharePointList1),
        Function.createDelegate(this, onFail)
    );
}

function onSuccessSharePointList1() {

        recNum = items.get_count();
      
      if(recNum != 0){
         var listItemEnumerator = items.getEnumerator();
         while(listItemEnumerator.moveNext()) {
                var oListItem = listItemEnumerator.get_current();
               
                $().SPServices({
                operation: "GetListItems",
                async: false,
                listName: "SharePoint List 2",
                CAMLViewFields: "<ViewFields><FieldRef Name='Worklocation'/></ViewFields>",
                CAMLQuery: "<Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + ReferenceID +
                                          "</Value></Eq></Where></Query>",
                completefunc: function (xData, Status) {
                  $(xData.responseXML).SPFilterNode("z:row").each(function() {
                    Worklocation = ($(this).attr("ows_Worklocation"));
                          
                        });
                }
                });
               
                 s = ..... (display all in table format)
 
              $("#resultTable").append(s);
              i++;
            }


}
0
 
Jayaraja JayaramanSharepoint Architect ConsultantCommented:
you can use list joints in caml query which u can make use of lookup.
http://blogs.msdn.com/b/kaevans/archive/2012/01/20/sharepoint-2010-caml-list-joins.aspx
this example is for 2010 you can make use of the same concept in 2013 as well
0
 
seebeelimAuthor Commented:
The solution given works well after tested and set live.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now