UpdateListItems - Invalid URL Parameter

Mar 22, 2013 at 12:25 AM
Hi,

I'm trying to write some variables to a SharePoint List but it's throwing up an "Invalid URL Parameter - The URL provided contains an invalid command or value. Please check the URL again" error.

At first I thought it may have something to do with the fact that one of the original variables contained table code but I stripped that out and just left the simple string's name, address and email. I can confirm that the user has write permissions to the lists "SavedSearches".

I also added a webURL parameter in, just in case, but it still had the same problem.

Can anyone see what might be causing the issue by looking at the function?
function CreateNewItem2(name, address, email) {
   
    
$().SPServices({
operation: "UpdateListItems",
async: false,
listName: "SavedSearches",
updates: "<Batch OnError='Continue'>" +
    "<Method ID='1' Cmd='Update'>" +
    "<Field Name='Title'>" + name + "</Field>" +
    "<Field Name='Email'>" + email + "</Field>" +
    "<Field Name='Address'>" + address + "</Field>" +
    "</Method>" +
    "</Batch><Where></Where>",
    completefunc: function(xData, Status) {
        alert(xData.responseText);
    }
        
});   
};
Thanks,
Dan
Mar 22, 2013 at 12:45 AM
Hard to determine where the error is happening (ex. Is before the call to SPServices or after is comes back). Is the error you mention below show. In your alert? Or somewhere else?

_____
Paul

Sent from mobile device.

Mar 22, 2013 at 1:05 AM
Thanks for the quick reply, Paul. The error appears in the alert.

Should I be writing the Site URL in the SPService jquery file or something? Or by default should it just be using the site that it's on? I just thought it was funny that it's saying there's an error with a URL Parameter yet I haven't entered a URL anywhere.
Mar 22, 2013 at 1:11 AM
Ok. Good. That tells me the call to the server was successful and SharePoint replied with an error.

I just looked at the forum post on the web which made a few items obvious to me. Looks like you are missing the ID inside the Method element (so that it knows what item to update). Also remove the <Where> tags. They are not needed - see the usage page for that Operation.

_____
Paul

Sent from mobile device.
Mar 22, 2013 at 1:54 AM
Thanks for your help, Paul. It's much appreciated!

I ended up rewriting the code using valuepairs instead of updates and it worked (well it worked more than it was, got to work out how to write the table html code to a list now!). Below's what I used instead (just in case anyone else experiences a similar issue)
function CreateNewItem2(name, address, email, tableCode) {
$().SPServices({
        operation: "UpdateListItems",
        webURL: "/sites/jeldwen/Masters/",
        async: false,
        batchCmd: "New",
        listName: "SavedSearches",
        valuepairs: [["Title", name],["Email", email],["Address", address],["Quote", tableCode]],
        completefunc: function(xData,status){
            alert(xData.responseText);
        }
    });        
};
Mar 22, 2013 at 2:02 AM
Glad to hear that. Interesting that in this last post your are creating a new item. On your initial post you were trying to update - during an update you have to tell SharePoint what item (ID) to update That was probably the reason for the original failure (and the invalid tags I reference prior )

Re: storing HTML
Tip: you will need to escape it before including it in the update.

Good luck.
_____
Paul

Sent from mobile device.
Mar 22, 2013 at 2:48 AM
ptavares wrote:
That was probably the reason for the original failure (and the invalid tags I reference prior )
Yep, I think that was probably it.

And thanks for the tip! That definitely helps
Coordinator
Mar 22, 2013 at 4:20 AM
Sounds like you guys worked it out. Great.

I do escape the values for you in SPServices if you use the valuepairs approach..

M.