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
seebeelimAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.