2

SP Services : UpdateListItems does not update the list item. The problem lies with the value that needs to be updated. The item is updated when the value is a normal text, but when it has some special characters like '&' the update doesn't work.

Any idea how to tackle this?

0

2 Answers 2

2

The problem isn't with SPServices. The problem is we are trying to use reserved characters.

Try using the following functions,

escapeColumnValue("Yourvalue")

// Escape column values
function escapeColumnValue(s) {
    return s.replace(/&(?![a-zA-Z]{1,8};)/g, "&");
    //(/&/g,'&');
}

OR

xmlencode("yourvalue");

Source

Hope this helps you :)

1
  • I modified your function as follows and it worked fine: function xmlencode(string) { return string.replace(/\&/g,'&'+'amp;');}
    – Shashant
    Commented Nov 7, 2013 at 9:23
0

In case it's useful to anyone, I had a similar problem with the < character, which is also reserved. The replace function wasn't working because the encoding for < is &lt;, so I used replace(/</g, '&' + 'amp;' + 'lt;') and it worked.

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.