0

Im trying to make this call in a app for accessing data from a list on the hosturl. but it not working, whats wrong in it?

    function execCrossDomainRequest() {

    var executor = new SP.RequestExecutor(appweburl);

    for (var i = 0; i < newsList.length; i++) {
        var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>";
        soapEnv += "    <soapenv:Body>";
        soapEnv += "        <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>";
        soapEnv += "            <listName>" + newsList[i].ListName + "</listName>";
        soapEnv += "            <query>";
        soapEnv += "                <Query>";
        soapEnv += "                    <OrderBy Override='TRUE'>";
        soapEnv += "                        <FieldRef Name='Created' Ascending='FALSE' />";
        soapEnv += "                    </OrderBy>";
        var currentDate = new Date();
        currentDate = currentDate.toISOString();
        soapEnv += "                    <Where>";
        soapEnv += "                        <And>";
        soapEnv += "                            <Or>";
        soapEnv += "                                <IsNull>";
        soapEnv += "                                    <FieldRef Name='PublicTo' />";
        soapEnv += "                                </IsNull>";
        soapEnv += "                                <Leq>";
        soapEnv += "                                    <FieldRef Name='PublicFrom' />";
        soapEnv += "                                    <Value Type='DateTime' IncludeTimeValue='True'>" + currentDate + "</Value>";
        soapEnv += "                                </Leq>";
        soapEnv += "                            </Or>";
        soapEnv += "                            <Or>";
        soapEnv += "                                <IsNull>";
        soapEnv += "                                    <FieldRef Name='PublicTo' />";
        soapEnv += "                                </IsNull>";
        soapEnv += "                                <Geq>";
        soapEnv += "                                    <FieldRef Name='PublicFrom' />";
        soapEnv += "                                    <Value Type='DateTime' IncludeTimeValue='True'>" + currentDate + "</Value>";
        soapEnv += "                                </Geq>";
        soapEnv += "                            </Or>";
        soapEnv += "                        </And>";
        soapEnv += "                    </Where>";
        soapEnv += "                </Query>";
        soapEnv += "            </query>";
        soapEnv += "            <queryOptions>";
        soapEnv += "                <QueryOptions>";
        soapEnv += "                    <IncludeMandatoryColumns>TRUE</IncludeMandatoryColumns>";
        soapEnv += "                </QueryOptions>";
        soapEnv += "            </queryOptions>";
        soapEnv += "            <viewFields>";
        soapEnv += "                <ViewFields>";
        soapEnv += "                    <FieldRef Name='ows_Title'/>";
        soapEnv += "                    <FieldRef Name='ows_Body'/>";
        soapEnv += "                    <FieldRef Name='show'/>";
        soapEnv += "                    <FieldRef Name='pic'/>";
        soapEnv += "                    <FieldRef Name='ows_FileLeafRef'/>";
        soapEnv += "                </ViewFields>";
        soapEnv += "            </viewFields>";
        var rowLimit = MaxAllNews;
        soapEnv += "            <rowLimit>" + rowLimit + "</rowLimit>";
        soapEnv += "        </GetListItems>";
        soapEnv += "    </soapenv:Body>";
        soapEnv += "</soapenv:Envelope>";

        var port = window.location.port;
        if (port.length <= 0)
            port = "";
        else
            port = ":" + port;

        var webservice = hostUrl + "/_vti_bin/lists.asmx";
        var imageURL = hostUrl + "/pics/";

        executor.executeAsync({
            url: webservice,
            method: "POST",
            dataType: "xml",
            data: soapEnv,
            async: false,
            contentType: "text/xml; charset=\"utf-8\"",
            complete: function (xData, status) {

                console.log('Success!');
            },
            error: function (xhr) {

                console.log('Error!  Status = ' + xhr.status);
            }

        });
    }
}
6
  • Last I checked (last year), SOAP was not available in SharePoint Online. Has this changed?
    – wjervis
    Commented Aug 14, 2014 at 11:46
  • I have used SOAP in sharepoint online before and it works, but i dont know if it works with cross domain scripting?
    – Anders
    Commented Aug 14, 2014 at 12:05
  • I have no experience with SOAP in SPO, so I cannot help you there. I have experience in REST, however. If you would still like the REST equivalent, I can help you with that.
    – wjervis
    Commented Aug 14, 2014 at 12:07
  • Okey, thank you, Yes i would like that. Can we enter a private chat?
    – Anders
    Commented Aug 14, 2014 at 12:12
  • We can continue here instead. So i want to translate my code to a REST call with the same caml query. How can i acchieve that?
    – Anders
    Commented Aug 14, 2014 at 13:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.