Thursday, June 12, 2008

Calling SharePoint webservices like lists.asmx using javascript

function QueryListEx(listGuid, fields, where, orderBy, rowLimit, extractRows)

  1. {
  2. var a = new ActiveXObject("Microsoft.XMLHTTP");
  3. if(a == null) return null;
  4. a.Open("POST", GetRootUrl() + "_vti_bin/DspSts.asmx", false);
  5. a.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
  6. a.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/dsp/queryRequest");
  7. var d = ''
  8. + "
  9. + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
  10. + "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope\/\">"
  11. +" "
  12. +" "
  13. +" 1.0"
  14. +" "
  15. +"
  16. +" service=\"DspSts\" document=\"content\" method=\"query\">"
  17. +" "
  18. +" "
  19. + ""
  20. + "
  21. +" xmlns=\"http://schemas.microsoft.com/sharepoint/dsp\">"
  22. +" + listGuid + "']\""
  23. +" resultContent=\"dataOnly\""
  24. +" columnMapping=\"attribute\" resultRoot=\"Rows\" resultRow=\"Row\">"
  25. +" + rowLimit + "\">"
  26. +" " + fields + ""
  27. +" " + where + ""
  28. +" " + orderBy + ""
  29. +" "
  30. +" "
  31. +" "
  32. + ""
  33. + "";
  34. a.Send(d);
  35. if (a.status != 200)
  36. return null;
  37. else
  38. {
  39. if (extractRows)
  40. return a.responseXML.selectNodes('//Row');
  41. else
  42. return a.responseXML;
  43. }
  44. }


function GetRootUrl()
{
var pathparts = document.location.pathname.split('/');
var url = 'https://' + document.location.hostname + '/' + pathparts[1] + '/';

return url;
}

special thanks to (click here for more help)

No comments:




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com