kurt343 kurt343 - 1 year ago 71
Javascript Question

Sharepoint2013 REST: How to handle problematic characters in GetByTitle('') list title?

I'm using the

endpoint quite heavily and have encountered a problem when the list title contains a problematic character(s).

I would prefer not to have to strip the characters during list creation but rather leave intact if possible.

Example addresses:
lists/GetByTitle('Custom Scores / weights test')

What is the correct way of handling this?

For clarity's sake, my code is:

  1. Creating the list.

  2. Attempting to create a list item by POSTing data to

The method I'm using to create ListItems in step2 is embedded within a module that I would prefer not to have to modify. It's unfortunately tightly coupled and changing everything to use List GUIDs or Internal Names, would be a large amount of work that I can't afford right now.

Please help :)

Answer Source

The solution I found to this problem was to URI encode the list title and duplicate apostrophes.

export const listURI = title => `/lists/GetByTitle('${encodeURI(title).replace(/\'/g, "''")}')`;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download