I am getting this error when trying to generate th...
# suitescript
n
I am getting this error when trying to generate the PDF "Error Parsing XML: The reference to entity \"c\" must end with the ';' delimiter" It works fine if I do it on the UI from the record. The PDF template also previews correctly. If I use the below it works but the images doesn't show up - only their URLs
Copy code
var pdfFile = renderer.renderAsString();
pdfFile = pdfFile.replaceAll('&', '&');

return render.xmlToPdf({xmlString: pdfFile});
How can I handle this?
b
you need to escape xml Character references
virtually guaranteed that you have a url with an & in there
you can manually do the replacement like you are trying, but you will learn that you dont actually want to replace every character, only the ones being used as values
the recommended alternative is to use one of freemarker's escape mechanisms
you can also use more simple mechanisms like the xml built in, but its deprecated because it makes it extremely easy to double escape
especially since the standard rendering by netsuite actually does its own escaping
n
What about using the ?url for escaping? I will need to add these in templates. The problem is the customer has made the templates. So, I will need to manually update each field. Also, yes, it is caused by file URL.
b
url escapes are different than xml escapes
dont assume that all escapes are interchangeable
n
${record.fileURLfield?url} will not work?
b
if you only cared about getting rid of the error, then yes, it will work
it wont actually make the url better
as an example, the url escape for & is %26
?url will replace the & in the url with %26, which does not contain a reserved character to cause problems in xml
your url however will be destroyed, because it now has a %26 where there was supposed to be an &
you probably will need to understander why escaping exists, both in general
and for url and xml
n
Thanks. Url and xml escape makes sense now. I will make the adjustments with the code/template.