0

I have a problem with getting items using SPServices:

<script src="servername/SiteAssets/jquery-1.10.0.min.js"></script>
<script src="servername/SiteAssets/sputility.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

    checkReservationStatus();
});
     function checkReservationStatus () {
     var weburl = $().SPServices.SPGetCurrentSite();
    var list = "listname";
$().SPServices({
    operation: "GetListItems",
    webURL: weburl,
    async:false,
    listName: list,
    // get list name from passed variable lisTitle
    CAMLViewFields: "<ViewFields><FieldRef Name='ID' /><FieldRef Name='Criteria_x0020_Met' /></ViewFields>",
    completefunc: function (xData, Status) {alert(Status);
        $(xData.responseXML).SPFilterNode("z:row").each(function(){
            status = $(this).attr("ows_Criteria_x0020_Met");
            alert(status);
        })
    }
})
if(status == "Yes") {
    return "Yes";
} else {
    return "No";
}
}  
 </script>

the completefunc argument "Status" returns an error and therefore never executes my logic.
What am I doing wrong?

0

console or alert xData.responseText like below,

    completefunc: function (xData, Status) { 
                            alert("Response:"+ xData.responseText); 
                            console.log("Response:"+ xData.responseText);
                            ...
    }

from the response you can find the error. Also make sure that following,

  • you are referring SP Service correctly [alert($().SPServices.SPGetCurrentSite());]
  • Listname & field names are correct. [internal names]
  • it returns undefined – Vusi85 Aug 31 '18 at 12:25
  • then try alert($().SPServices.SPGetCurrentSite()); in $(document).ready function – Vishnu S Aug 31 '18 at 12:28
  • it returns my site name – Vusi85 Aug 31 '18 at 12:44
  • that means SP Services refereed correctly. Now check the list name & field names given are correct. – Vishnu S Aug 31 '18 at 12:49
  • list name is returning correctly. Do I use internal list column name like this Criteria_x0020_Met or use Display name in FieldRed Name="<column name>"?? – Vusi85 Aug 31 '18 at 12:54
0

Here is my test code which works fine, you could try it.

<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {

            checkReservationStatus();
        });
        function checkReservationStatus() {
            var weburl = _spPageContextInfo.webAbsoluteUrl;
            var list = "MyData1";
            $().SPServices({
                operation: "GetListItems",
                webURL: weburl,
                async: false,
                listName: list,
                // get list name from passed variable lisTitle
                CAMLViewFields: "<ViewFields><FieldRef Name='ID' /><FieldRef Name='Criteria_x0020_Met' /></ViewFields>",
                completefunc: function (xData, Status) {
                    alert(Status);
                    $(xData.responseXML).SPFilterNode("z:row").each(function () {
                        status = $(this).attr("ows_Criteria_x0020_Met");
                        alert(status);
                    })
                }
            })
            if (status == "Yes") {
                return "Yes";
            } else {
                return "No";
            }
        }
    </script>
  • I tried it but still the Status parameter returns error and the doesn't hit out conditions. – Vusi85 Sep 4 '18 at 7:18
  • Insert a breakpoint to completefunc and monitor the detailed error info in xData. – Lee_MSFT Sep 4 '18 at 7:43
  • I managed to fix it. look at the following code: SP was parsing special characters that were causing issues. I'm sorted now. var specialCharsDeleted = xData.responseText.replace(/&#11;/g, ''); var xmlDoc = $.parseXML( specialCharsDeleted ); $(xmlDoc).SPFilterNode("z:row").each(function () { status = $(this).attr("ows_Criteria_x0020_Met"); }); – Vusi85 Sep 4 '18 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.