Solved

Retrieve data from two SharePoint list using jquery

Posted on 2014-07-20
5
5,720 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)

749 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