Friday, September 19, 2014

Get “Multiple lines of text” field value using SharePoint 2013 REST services

If we get list item from SharePoint REST services, we may get unexpected results for “Multiple lines of text” fields. Let’s take the scenario given below. I used following service to get results.
https://sp13/sites/dev/_api/web/lists/getbytitle('r')/items(4)
Instead of the field value we may get a escaped html string like below.
image
The reason for this behavior is that the column is enabled for rich text. If we want to keep the rich text input, we may need to escape the string using RegEx for some JavaScript functionality. For an example we can use following script to display expected comment in a textbox.
tmpComment = data.d.AGMComment != null ? data.d.AGMComment.replace("'", "") : "";
$('#txtApprovalComments').val($(tmpComment).text());
But if we don’t need the rich text behavior we can simply make the column to accept only plain text.
image
After modifying column settings as shown above, following will be the output from the same service call
image

No comments: