Solved

Retrieve data from two SharePoint list using jquery

Posted on 2014-07-20
5
5,387 Views
Last Modified: 2014-08-06
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
Comment
Question by:seebeelim
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:Nuno Rogado
ID: 40214143
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
 
LVL 8

Expert Comment

by:Jayaraja Jayaraman
ID: 40218010
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
 

Accepted Solution

by:
seebeelim earned 0 total points
ID: 40219263
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
 
LVL 8

Assisted Solution

by:Jayaraja Jayaraman
Jayaraja Jayaraman earned 200 total points
ID: 40220129
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
 

Author Closing Comment

by:seebeelim
ID: 40243182
The solution given works well after tested and set live.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question