updateListItems multiline text returning blank and 'undefined'

Oct 8, 2013 at 4:26 PM
This code pulls from z:row and creates a new item in another list. Title, ID, and Modified are working as expected ... 'RichText' is a rich text box on receive end AND on push end. When CreateNewItem fires all rows are created and all columns but not the 'RichText' it is either blank or has text of 'undefined'. I have matched the text type in the new list with the same result.
$().SPServices({
                operation: method,
                async: false,  
                webURL:"https://siteaddress",
                listName: list,
                CAMLViewFields: fieldsToRead,
                  CAMLQuery: query,
                        completefunc: function (xData, Status) { 
                        $(xData.responseXML).SPFilterNode("z:row").each(function() { 
                            
                            var name = ($(this).attr("ows_Title"));
                            var gspID = ($(this).attr("ows_ID"));
                            var modified = ($(this).attr("ows_Modified"));
                            var richText = ($(this).attr("ows_RichText"));
                                                     
                            
                        CreateNewItem(name,gspID,modified,richText);
                        });                
                    }
        });

}

function CreateNewItem(name,gspID,modified,richText) {
    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        batchCmd: "New",
        listName: "NewList",
        valuepairs: [["OldModified", modified], ["oldID", gspID], ["Title", name], ["RichText", richText]],
        completefunc: function(xData, Status){ 
        ""
        }
    
    });
}
Coordinator
Oct 8, 2013 at 7:35 PM
Greg:

It could be that your RichText column is not in fieldsToRead, or that it has another name. Can you see it in the traffic on the Net tab in the IE DEv Tools or Firebug?

M.
Oct 8, 2013 at 10:28 PM
I double checked that I am using 'name' and not 'display name' - don't know how to check if it is in fieldsToRead. It is passing in the traffic the request body has the field name then drops to line two and wraps the contents in a <div> tag ... could that be the issue? It doesn't show in the Response Body.
Coordinator
Oct 8, 2013 at 11:45 PM
fieldsToRead is in your code, so you're defining it somewhere. If is doesn't have RichText in it, then you won't get that column back.

M.
Oct 9, 2013 at 1:54 PM
Edited Oct 9, 2013 at 1:58 PM
doh ... thanks for your patience for people who don't bother to go back and read their code. Yes, I do have it referenced in my var fieldsToRead. I pass the data into a table in a CEWP and the RichText is showing there. Here is my complete code:
function createGateway()
{
        
        var method = "GetListItems";

        //located on another site collection        
        var list = "SourceList";
        

         
        var fieldsToRead =     "<ViewFields>" +
                                "<FieldRef Name='Title' />" +
                                "<FieldRef Name='ID' />" +
                                "<FieldRef Name='RichText'/>" +
                            "</ViewFields>";
                            
        
        var query = "<Query>" +
                        "<Where>" +
                            "<Eq>" +
                                "<FieldRef Name='Filter'/><Value Type='Text'>Criteria</Value>" + 
                            "</Eq>" +
                        "</Where>" +                                                
                        "<OrderBy>" + 
                            "<FieldRef Name='ID'/>" +
                        "</OrderBy>" +
                    "</Query>";

        
        $().SPServices({
                operation: method,
                async: false,  
                webURL:"site address of source data",
                listName: list,
                CAMLViewFields: fieldsToRead,
                  CAMLQuery: query,
                        completefunc: function (xData, Status) { 
                        $(xData.responseXML).SPFilterNode("z:row").each(function() { 
                            
                            var name = ($(this).attr("ows_Title"));
                            var sourceID = ($(this).attr("ows_ID"));
                            var sourceModified = ($(this).attr("ows_Modified"));
                            var richText = ($(this).attr("ows_RichText"));
                                                     
                            
                            AddRowToTable(name,sourceID,sourceModified,richText);
                            CreateNewItem(name,sourceID,sourceModified,richText);
                        });                
                    }
        });

}

function AddRowToTable(name,sourceID,sourceModified,richText)
{
    $("#projectTable").append("<tr align='left'>" + 
                                "<td> "+ sourceID + name + sourceModified + richText +"  </td>" +
                               "</tr>");
                                
}
function CreateNewItem(name,sourceID,sourceModified,richText) {
    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        batchCmd: "New",
        listName: "ReceiveList",
        valuepairs: [["SourceModified", sourceModified], ["SOURCEID", sourceID], ["Title", name], ["RichText", richText]],
        completefunc: function(xData, Status){ 
        ""
        }
    
    });
}
</script>

<table id="projectTable"></table>
Coordinator
Oct 9, 2013 at 2:21 PM
Working now?

M.
Oct 9, 2013 at 3:02 PM
No .. I always had RichText referenced in the var fieldsToRead - still not working. The data populates in the table in the CEWP but gets created in the ReceiveList as blank or it adds text 'undefined' - am I trying to do too much at once?
Coordinator
Oct 9, 2013 at 3:07 PM
I'm not sure what's happening. I think you said that RichText is not returned in the ResponseBody. If that's the case, then you don't have the column name right in fieldsToRead.

M.
Oct 9, 2013 at 4:09 PM
Strange that it shows up in the table on the CEWP but passes blank or undefined to the CreateNewItem function - I'll test without passing to table and see what I get in the traffic - sigh
Oct 9, 2013 at 4:14 PM
Also, you might want to check the html of the RichText variable to be sure that you are passing valid content to that type of field. I have always had to be sure that my text was wrapped in a div element and sometimes that gets stripped out depending on what you are doing.

Dan
Coordinator
Oct 9, 2013 at 4:16 PM
It also could be an escaping thing.

M.
Oct 24, 2013 at 5:39 PM
I set this aside for a bit - Back and still frustrated. I have tested this with several 'Note' type columns with the same result. The request body is passing the field (with a whole lot of html mark-up) the response body also has the field. Example of how one of the response bodies starts: <ul> <li&gt - and nothing is passed to the receiving list. In other cases it's just a <div> tag and the response has nothing. I am thinking to strip the html tags from the string and make the receiving column a plain multiline text box.
Oct 24, 2013 at 6:01 PM
Got it working. I used jQuery text() -- var richText = $($(this).attr("ows_RichText")).text();
Hope this helps someone! I have less hair now.