1

I'm testing a basic insert new list item to custom list when user landed sub-sub site.

JS libraries are both reference in master page and path work perfectly. First I'm getting Synchronous XMLHttpRequest warning and the list is not updating.

Would appreciate any help. TIA.

    function res_scr(val) {
    $().SPServices({
        operation: "UpdateListItems",
        webURL: "http://portal/lists",
        async: false,
        batchCmd: "New",
        listName: "MyPortalAwards",
       valuepairs: [["Title", val]],                
       completefunc: function (xData, Status) {
         if (status == "success") {
            console.log("Data Saved! and Please check your List");
         }
         else {
            console.log("Unable to submit your request at this time.");
         }
        }
    });
}




$( document ).ready(function() {

    if(window.location.href.indexOf("PoliciesCircularsMemo") >= 0)  {

        res_scr('RES-POLI-CIRC-MEMO');
    }

});
1
  • The script run with webURL set to root site. webURL:"/";
    – Jonathan.B
    Commented Aug 18, 2015 at 11:00

2 Answers 2

1

The script you have written is for creating new list item. To update the list items use the below code:

$(divId).html(waitMessage).SPServices({
operation: "UpdateListItems",
listName: testList,
ID: ID,
valuepairs: [["Title", now]],
completefunc: function (xData, Status) {
    var out = $().SPServices.SPDebugXMLHttpResult({
        node: xData.responseXML,
        outputId: divId
    });
    $(divId).html("").append("<b>This is the output from the UpdateListItems operation:</b>" + out);
    $(divId).append("<b>Refresh to see the change in the list above.</b>");
}
});

SPServices site reference

Also you can easily find other examples. The important part--ID is required while updating the items.

3
  • Apology for the confusion, I wanted to insert new item in the root list but I'm getting the error. Was also thinking that it will not work since the script triggered in sub-sub site where the list "MyPortalAwards" don't exist. Appreciate the link though.
    – Jonathan.B
    Commented Aug 5, 2015 at 7:04
  • You should look into another parameter of SPServices "webUrl". Using this you could achieve your functionality.
    – Pushpendra
    Commented Aug 5, 2015 at 7:28
  • Added the webURL: "portal/lists" but it giving 500 error. Any idea?
    – Jonathan.B
    Commented Aug 11, 2015 at 12:17
0

You're using the correct operation and batchCmd. You need to remove the word lists from your webURL. Then you need to change your status variable to Status with a capital S.

function res_scr(val) {
    $().SPServices({
        operation: "UpdateListItems",
        webURL: "http://portal",
        async: false,
        batchCmd: "New",
        listName: "Announcements",
       valuepairs: [["Title", val]],                
       completefunc: function (xData, Status) {
         if (Status == "success") {
            console.log("Data Saved! and Please check your List");
         }
         else {
            console.log("Unable to submit your request at this time.");
         }
        }
    });
}

$( document ).ready(function() {
    if(window.location.href.indexOf("PoliciesCircularsMemo") >= 0)  {
        res_scr('RES-POLI-CIRC-MEMO');
    }
});

Your Answer

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

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