Friday 4 November 2011

Javascript Content Query over Web Applications

 

Sometimes you want to show some items from a List in another Site Collection or Web Application (or even another Farm). This can't be done with out of the box webparts. The next javascript which you can paste in de default content editor webpart (source editor) can help you in this situation.
  1. Go to the site where you want to show your list items (not the location of the list)
  2. Put this file in a document library in your site
  3. Edit your page and paste a content editor wepart on your page
  4. Go to source editor (of the webpart properties of the content editor webpart)
  5. Put the next code into your content editor webpart

<script type="text/javascript" src="http://mysite/documentlibrary/jquery-1.3.2.min.js"></script> <script type="text/javascript">    $(document).ready(function() {        var soapEnv =            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \                <soapenv:Body> \                     <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \                        <listName>libraryname</listName> \                        <viewFields> \                            <ViewFields> \                               <FieldRef Name='Title' /> \                           <FieldRef Name='ID' /> \                           </ViewFields> \                        </viewFields> \                    <rowLimit>5</rowLimit> \                    </GetListItems> \                </soapenv:Body> \            </soapenv:Envelope>";         $.ajax({            url: http://corporatesite/site/_vti_bin/lists.asmx,            type: "POST",            dataType: "xml",            data: soapEnv,            complete: processResult,            contentType: "text/xml; charset=\"utf-8\""        });    });     function processResult(xData, status) {        $(xData.responseXML).find("z\\:row").each(function() {            var liHtml = "<li><a href=\"http://corporatesite/site/list/listname/DispForm.aspx?ID=" + $(this).attr("ows_ID") + "\">" + $(this).attr("ows_Title") + "</a></li>";            $("#tasksUL").append(liHtml);        });    }</script> 

No comments:

Post a Comment