UpdateListItems Not Updating List?

Jan 28, 2014 at 9:49 PM
Edited Jan 29, 2014 at 6:37 PM
I have a strange one here. Here's the code I'm using:
$().SPServices({
    operation: "UpdateListItems",
    async: false,
    batchCmd: "Update",
    listName: list,
    ID: prog,
    valuepairs: [["Notes", $("#notes").html()]],
    completefunc: function (xData, Status) {
        alert($("#notes").html());
    }
});
notes is a rich text multiline field in a dialog form that contains formatted text. When I step through the code execution it looks like the HTML is preserved (it appears as expected in the alert).

list is the display name of the list I want to update.

prog contains the ID I want to update in list.

When I run the above, however, nothing gets written to the target list, though if there was existing text, it gets wiped out. If I switch the value pair to ["Notes", $("#notes").text()], the text does appear in the list, but none of the formatting comes along with it. Am I missing something obvious?
Jan 29, 2014 at 11:42 PM
You're not doing any error checking - my assumption is your getting a error. Probably something that says invalid XML message.

When you write HTML data to a list, you need to escape the HTML so that it can be sent in the XML message. I think sharepoint has a method that you can use - but I don't remember what that is right now.


--
Paul T.

-- Sent from Mobile

Marked as answer by AurumPotabile on 1/30/2014 at 4:43 AM
Jan 30, 2014 at 11:47 AM
Paul, thanks so much for the help! It was precisely what I needed. You're right-- there was no escaping going on. I completely forgot about the conversion to XML prior to submitting to the list. In order to help others possibly struggling with this same roadblock, here's the revised (and working!) code:
var dfNotes = CKEDITOR.instances.notes.getData();

$().SPServices({
    operation: "UpdateListItems",
    async: false,
    batchCmd: "Update",
    listName: list,
    ID: prog,
    valuepairs: [["Notes", $("#notes").text(dfNotes).html()]],
    completefunc: function (xData, Status) {
        alert($("#notes").html());
    }
});
The first line references a rich text editor field that contains newly modified text. Note the slight difference in the valuepairs line where it now uses .text().html() to escape the text for transmission via XML.

Thank you again, Paul! You saved me a lot of time.
Jan 30, 2014 at 12:46 PM
Interesting way of escaping HTML... Did not realize that .text() was also a setting - I always thought it was only a getter.

Thanks for posting back your solution...

/Paul.