+ Start a Discussion
SteveBowerSteveBower 

Fix for Documents and Textarea Fields in Ajax toolkit.

So, I couldn't get Documents to work properly (see my previous posts), so I decided to recode it to use several Textarea fields. Turns out that the same issue of "chunking" long return results occurs for either Documents, Textareas, and (although I haven't tested it, probably Attachments) as well.

This small change to the sforceclient.js file solves these problems as well as re-balancing the "base64" datatype so that since you don't encode() your data going in, you don't have to decode() it yourself coming out. 

Thanks, Steve Bower.

Sforce.DOM.ParseVal = function(value, name ,desc) { var fldDef = desc.fieldMap.getItem(name.toLowerCase()); if (fldDef == null) { var cr = desc.childRelationships.getItem(name.toLowerCase()); if (cr != null) { //This is an object definition for a child relationship //This should be a queryResult with all the records of the child object return new Sforce.QueryResult(value); } else { return Sforce.Serialization.DeserializeBean(value); } } else { if (value == null || value.length == 0) { if (fldDef.type == "date" || fldDef.type == "datetime") { return null; } else { return value; } } var fldType = fldDef.type; /* Note remove textarea from this block. */ if (fldType == "string" || fldType == "picklist" || fldType == "multipicklist" || fldType == "combobox" || fldType == "reference" /*|| fldType == "textarea" */|| fldType == "phone" || fldType == "id" || fldType == "url" || fldType == "email") { return value; } else if (fldType == "boolean") { if (value.toLowerCase() == "false") { return false; } else { return true; } } else if (fldType == "currency" || fldType == "double" || fldType == "percent") { return parseFloat(value); } else if (fldType == "date" || fldType == "datetime") { return Sforce.Util.FromIsoDateTime(value); /* Added. Steve Bower. */ } else if (fldType == "textarea" ) { if (typeof value == "object") { return value.textContent; } else { return value; } } else if (fldType == "base64") { var b64 = new Sforce.Util.Base64(); if (typeof value == "object") { return b64.decode(value.textContent); } else { return b64.decode(value); } /**/ } else { return value; } } };