cubanGuy cubanGuy - 8 months ago 70
Javascript Question

REST Call with values containing apostrophe

I using REST and ajax to fetch data from SharePoint using the ablve:

https:xxxxxxxx/_vti_bin/ListData.svc/RMSD_Tasks?$orderby=IssueValue asc,StatusValue desc&$filter="+dropValue+" eq '"+secondFilterVal+"'&groupby=IssueValue/StatusValue

Everything works just fine, except one case. Sometimes the value of secondFilterVal is "Manager's Bulletins" with an apostyrophe. When I make the call I get a bad request message. What can I do here? Unfortunately, the text "Manager's Bulletins" can't be changed. I was thinking about using "$filter=substringof.....", but it works so well with everything else. Thansk!


Thanks @Lauri and @charlietfl for the comments. The information @charlietfl gave me was specially useful, because it opened my eyes to different options, and encodeURIComponent() was the way to go. Reading MDN's encodeURIComponent() and this great link to REST Filters helped me solve my issue using the above code:

var str = fixedEncodeURIComponent("Manager's Bulletins");

function fixedEncodeURIComponent(src) {
return encodeURIComponent(src).replace(/[!'()*]/g, function (c) {
    return '%' + c.charCodeAt(0).toString(16) + '%' + c.charCodeAt(0).toString(16);


For some strange reason you need the apostrophe twice: The result Manager%27%27s%20Bulletins works perfectly.