Top Menu

Wednesday, September 19, 2012

JQuery: Read list Item via Lists.asmx

Following JQuery script is to get list items using Lists.asmx web service in MOSS 2007:
<script type="text/javascript" src="/Scripts/jquery-1.8.1.min.js"></script>
<script type="text/javascript">

//This function will call when OK button will be pressed on a List's default form (e.g. EditItem.aspx).

function PreSaveItem()
{
 var project = "Project A";
 
 GetProjectID(project);
 
 return true;
}

function GetProjectID(project){

var soapEnv = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
<soap:Body> \
    <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
        <listName>Teams</listName> \
        <query><Query><Where><Eq><FieldRef Name='Project'/><Value Type='Text'>"+ project +"</Value> </Eq></Where></Query></query> \
        <viewFields> \
            <ViewFields> \
                <FieldRef Name='ID' /> \
                <FieldRef Name='Title' /> \
            </ViewFields> \
        </viewFields> \
        <rowLimit>99999</rowLimit> \
        <queryOptions xmlns:SOAPSDK9='http://schemas.microsoft.com/sharepoint/soap/' ><QueryOptions/> \
        </queryOptions> \
    </GetListItems> \
</soap:Body> \
</soap:Envelope>";

jQuery.ajax({
url: "/itsglobal/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: ResultMethod,
contentType: "text/xml; charset=\"utf-8\""
});

}

function ResultMethod(xData, status) 
{

    if (status=="success")
    {
        alert(status);
        $(xData.responseXML).find("z\\:row").each(function() 
        {
            alert($(this).attr("ows_ID"));
        });
    }

}

</script>
I have copied this script from the internet and have tweaked it a bit to work with JQuery 1.8 version.

No comments:

Post a Comment

Official SharePoint Documentation

I have recently contributed to the official SharePoint documentation for developement. Check it out here: https://docs.microsoft.com/en-us...