You need to sign in to do that
Don't have an account?
Federico Larsen
Retrieve Document
Hi,
i am trying to retrieve a document (text/html) and use its content, but i cant do it yet, this is the code i am using.
Code:
i am trying to retrieve a document (text/html) and use its content, but i cant do it yet, this is the code i am using.
Code:
function getHeadHTML(){ var docs = sforceClient.Retrieve("Body","Document",[_tpl_doc_ID]); if (docs != null && docs.length > 0){ var doc = docs[i]; var body64 = doc.get("Body"); var body = decode64(body64.textContent); return body; } else{ alert("Error."); } }
The upshot of this (and there are other messages on this in the boards as I was trying to figure it out which give sample code, etc.) is that the code in this posting:
http://forums.sforce.com/sforce/board/message?board.id=general_development&message.id=6336
fixes the document problems and does away with your need to decode the Base64 stuff yourself. Just take that code and throw it into a script tag after the reference to sforceclient.js. It overrides the Salesforce provided Sforce.DOM.ParseVal function with a new version with some simple fixes.
My retrieve code now looks like:
Code:
And I think your code would be:
I watch the message borad you told me and I solved my problem.
my function now is like this, since I only have to retrieve one document, specified in the _tpl_doc_ID global constant
Code:
I attach de code.
Thanks for your comments about this.Code:
function decode(input){
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;
var base64test = /[^A-Za-z0-9\+\/\=]/g;
if (base64test.exec(input)) {
alert("There were invalid base64 characters in the input text.\n" +"Valid base64 characters are A-Z, a-z, 0-9, '+', '/', and '='\n" +"Expect errors in decoding.");
}
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
var stringBuffer = [];
do {
enc1 = keyStr.indexOf(input.charAt(i++));
enc2 = keyStr.indexOf(input.charAt(i++));
enc3 = keyStr.indexOf(input.charAt(i++));
enc4 = keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
stringBuffer.push(String.fromCharCode(chr1));
if (enc3 != 64) {
stringBuffer.push(String.fromCharCode(chr2));
}
if (enc4 != 64) {
stringBuffer.push(String.fromCharCode(chr3));
}
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);
output = stringBuffer.join("");
return output;
}