How to get Rich Text field in SharePoint 2013 using JSOM?

Hi Sharepointers,

In this blog, I will share the script to get Rich text field using JSOM.

var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, “sp.js”);
function Initialize()
{
//Use for Cross Site Data
var siteUrl = /sites/MySPSite/CurSite;

//clientContext = new SP.ClientContext.get_current();
clientContext = new SP.ClientContext(siteUrl);
web = clientContext.get_web();
var list = web.get_lists().getByTitle(“Employee”);
var camlQuery = new SP.CamlQuery();
var q = “<FieldRef Name=’JoiningDate’ Ascending=’False’/></OrderBy></Query><RowLimit>1</RowLimit></View>”;
camlQuery.set_viewXml(q);
this.listItems = list.getItems(camlQuery);
clientContext.load(listItems, ‘Include(Id, Title, Body, Blurb)’);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListItemsLoadSuccess(sender, args) {
var listItemEnumerator = this.listItems.getEnumerator();
while (listItemEnumerator.moveNext()) {
var item = listItemEnumerator.get_current();
var itemId = item.get_id();
var curTitle = item.get_item(‘Title’);
var curBody = item.get_item(‘Body’);

}

$(‘#postTitle’).text(curTitle);
$(‘#postBody’).html(curBody);
}

function onQueryFailed(sender, args) {
alert(‘request failed ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
}

Happy SharePointing Folks 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *