Validate before render.xmlToPdf

Looking to validate input before render.xmlToPdf.

I’ve tried using N/xml to parse it (and catch issues), then feed the resulting XML document into render.xmlToPdf, but there is stuff that N/xml seems to accept, that render.xmlToPdf will completely die on.

Beginner Asked on September 27, 2019 in SuiteScript.
Add Comment
1 Answer(s)
When you are pasing an object with 'N/xml' you need to consider this object would be multiple levels deep most of the time, then you may need a function to loop througth the object and parse/excape each individual string/values.

This function works for most of the use cases you will find, however, this would not consider the cases where the object keys may need to be parsed aswell in which case you will need a more complex/robust function that will basically mutate your entire object into a new one taking care of the keys also.
 * Escape a Multiple Levels Object to make it XML Compliant
 * @param {Object[]} paramObject
 * @return {Object[]}
function escapeXMLObject(paramObject){

    for(var nKey in paramObject){

        if (paramObject[nKey] != null && typeof paramObject[nKey] === 'string') {

            paramObject[nKey] = xml.escape({xmlText: paramObject[nKey]});

        }else if(paramObject[nKey] != null && typeof paramObject[nKey] === 'object') {

            paramObject[nKey] = escapeXMLObject(paramObject[nKey]);



    return paramObject;

Rookie Answered on September 27, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor