Solved

Retrieve data from two SharePoint list using jquery

Posted on 2014-07-20
5
5,052 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
The solution given works well after tested and set live.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now