Need help inserting rich text into table.

Dec 13, 2014 at 8:28 PM
I'm new to both SP2013 & jquery and have been struggling with this issue to no avail over the last several days and would appreciate any and all help. My goal is to retain the formatting of an InfoPath rich text input box when I use GetListItems to put the text in a table on an .apsx page within the same site. I was never able to get Json to work for me, so I’m going about it the old way, essentially as follows:
function get() {
    var method = "GetListItems";
    var webURL = $().SPServices.SPGetCurrentSite() ;
    var list = "Knowledge Submissions";
    var fieldsToRead = "<ViewFields><FieldRef Name='ID' /></ViewFields>";
    var query = "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>4</Value></Eq></Where></Query>";

    $().SPServices
    ({
        operation: method,
        async: false,
        webURL: webURL,
        listName: list,
        CAMLViewFields: "<ViewFields Properties='True' />",
        CAMLQuery: query,

        completefunc: function (xData, Status) {
            $(xData.responseXML).SPFilterNode("z:row").each(function () {
                var ID = $(this).attr("ows_ID");
                var analysis = $(this).attr("ows_Analysis");                         
                $("#cAnly").text(analysis);                                                                           
});
        }
    });
}
This pulls through all the html tags, so it’s pretty much garbage. I’ve tried the following as well:
var analysis = $($(this).attr("ows_Analysis")).text(); 
This just gives me the text without line breaks or formatting. Would appreciate some guidance. Thanks.
Coordinator
Dec 13, 2014 at 9:00 PM
You don't have the Analysis column in the ViewFields explicitly, so are you sure you're getting data back for it? If you are, you definitely will get the HTML that's in the field, which is what is store for Rich Text.

So it sounds like you are getting what you want, but the issue arises when you try to do something with it?

M.
Dec 14, 2014 at 12:01 AM
Edited Dec 14, 2014 at 12:02 AM
By way of example, the original submission in an Infopath form looked like this:

The Most Traffic-Jammed Cities In The U.S.

The following was borrowed from a Forbes article for purposes of illustration. The top 3 U.S. cities with the worst gridlock are as follows:
  1. Los Angeles, CA
  2. Honolulu, HI
  3. San Francisco, CA
Using the 1st set of code, I get this.

<html> <p>< strong> The Most Traffic-Jammed Cities In The U.S </strong></p> <p style="text-align:justify;"> The following was borrowed from a Forbes article for purposes of illustration. The top 3 U.S. cities with the worst gridlock are as follows:</p> <ol> <li> Los Angeles, CA </li> <li> Honolulu, HI </li> <li> San Francisco, CA </li> </ol>

When I changed
var analysis = $(this).attr("ows_Analysis"); 
to
var analysis = $($(this).attr("ows_Analysis")).text();
I got the following:

The Most Traffic-Jammed Cities In The U.S. The following was borrowed from a Forbes article for purposes of illustration. The top 3 U.S. cities with the worst gridlock are as follows: Los Angeles, CA Honolulu, HI San Francisco, CA

I did add the Analysis column to the View Fields, but it didn't seem to make a difference. The last line
$("#cAnly").text(analysis);                                                                           
inserts this field into a table by using the td id = "cAnly. My goal is to insert the text in the original format into my table.
Coordinator
Dec 14, 2014 at 12:25 AM
Because it's HTML, you want to use:
$("#cAnly").html(analysis);
M.
Marked as answer by awschneider on 12/13/2014 at 6:55 PM
Dec 14, 2014 at 1:55 AM
It worked!! I could have sworn I'd tried that. Thank you, thank you, thank you!!!!